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 > Regular sequence of long jumps in thumb mode?

#95840 - Dwedit - Mon Jul 31, 2006 8:15 am

What's the best way to create a sequence of long jump instructions in THUMB mode without destroying any registers? The jumps are too long for the b instruction, and THUMB doesn't have ldr pc,=xxxx.
Pretty much I want constant size for each jump, so I can later do something like:

function_1 = base + 0*N
function_2 = base + 1*N
function_3 = base + 2*N
function_4 = base + 3*N
function_5 = base + 4*N
...
In fact, I don't really care if the code that does the jumps is in thumb or not, I just want to call a jump FROM thumb, TO thumb code.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#95846 - gladius - Mon Jul 31, 2006 9:06 am

If you are on the arm9, there are a few options. ldr pc, =blah, will do the thumb/arm switch for you, so you can hop over to arm mode with a bx pc placed on a 4 byte boundry. ie.
Code:

.align 4
bx pc ; jumps to the ldr
.arm
ldr pc, =0xbadf00d

If you are on an arm7 things get a bit more tricky. You could use a variant of the above and just store r0 on the stack, then bx r0. But if you can't modify the stack or any registers, you might be in trouble :).

#96060 - Dwedit - Tue Aug 01, 2006 2:51 am

I guess I'll just push lr, bl, then pop pc. Thanks.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."