[David] is building a project with an OLED, a keyboard, and an RP2040. He’s perfected a scanning routine in C to work with the keyboard, but he still had some places he wanted to use even lower-level instructions. That was as good an excuse as any to experiment with inline assembly language inside the C program.
The goal was to grab the keyboard’s input and stick it into a memory address register so the data at that address could be shown on the display. However, there was a complication because memory access of this type has to be word-aligned.
Sure, you could mask the low bits of the address, do the read, and then set an index to pick the specific byte, but assembly is easy, and it is good to know how to put it in your code, anyway.
[David] only needed one instruction that is meant for byte access, so as assembly embeddings go, this was quite simple. We’ve done similar things for Linux, although, of course, the Arm assembly language here is different than what we used.
You probably don’t need assembly for every project. But it is nice to know how to do it when you need it. Many people think you don’t need to learn assembly these days, but we mostly disagree.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)