gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Loading halfwords

#11679 - poslundc - Wed Oct 15, 2003 7:44 pm

When loading two sequential halfwords, the temptation is to instead of using two ldrh commands, to use a single ldr command and then split the contents of the loaded register. (In fact, sometimes this is the only choice as ldr has a much more versatile addressing mode than ldrh does.)

My question is whether this is worthwhile, and what the fastest way to do it is. My current strategy is pretty straightforward and uninventive:

Code:

   ldr      r1, [r0]         @ r1 <- combined word
   mov      r2, r1, asr #16   @ r2 <- second halfword
   mov      r1, r1, lsl #16      @ shift off upper 16 bits
   mov      r1, r1, asr #16   @ r1 <- first halfword


But I'd imagine this could be improved upon. Any suggestions?

Dan.

#11681 - momo - Wed Oct 15, 2003 8:27 pm

hi,

if you have no problems with signed-extension, you can use this
Code:

 ldr   r0,[r3]
 mov   r1,r0 lsr 16
 bic   r0,r0,r1 lsl 16


momo