Blah
Free supporter
- 1,924
- Posts
- 12
- Years
- Unknown Island
- Seen Feb 19, 2025
What's the most idiomatic way to clear all but the least significant byte from a register?
I currently have two thoughts:
Code:lsl r1, r1, #0x18 lsr r1, r1, #0x18
Code:mov r0, #0xFF and r1, r0
I like the first because I don't have to use a second register, but the second is a bit clearer, and I'm guessing, faster. Which one should I go with? Or perhaps even a different alternative I haven't considered?
For the first one, you're losing the significant byte.
You've got the shifts backwards. Clearing the last byte would be done like this:
Code:
lsr r0, r0, #0x8
lsl r0, r0, #0x8
Say you have FFFF. Shifting it right 8 bits (1 byte) gives you 0FFF, then you shift it left 8 more bits to get FFF0 :)