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 > Branch out of range Error

#7781 - funkeejeffou - Tue Jun 24, 2003 4:42 pm

Hi,

I'm using goldroad, and I've been implementing a long functiun in Iwram.
The problem is when I call it from ROM code with a "bl my_functiun", golroad generates me an error saying the branch is out of range.
My textareas, pool splitting as well as my copy data loops are fine since they've been working well till now.
Is it normal that the assembler cannot branch a label as far as this?
If so, should I manually change the PC and stack the oldest one so I can return after my functiun finished?
In this case, should I take care of the pipelining and substract 12 from the PC (it's ARM code)?
Also thought of this, what about :
Code:
addr r0, my_functiun
bl r0


If this works, then WHY does "bl my_functiun" doesn't work?

Thanks

#7787 - DekuTree64 - Tue Jun 24, 2003 5:55 pm

bl can only reach 24 bits, and ROM starts at 0x8000000, and IWRAM starts at 0x3000000, and those are farther apart than 24 bits can reach. I'm not sure if this is how you're supposed to do it, but I just use
Code:

ldr r0, =FuncName
mov lr, pc
bx r0

and it seems to work fine. Since pc points to 2 instructions ahead, when that mov lr, pc executes, pc is at the instruction after the bx r0, which is where you would want to return to. And as far as I know, you can bl to a register, so you have to use a bx.

#7944 - funkeejeffou - Sun Jun 29, 2003 5:07 am

It works great DekuTree64 !!!
Many thanks.

Haven't tested it in Thumb, but I suppose it should work as the pc will be set to the current instruction + 4 bytes, right?

#7958 - torne - Sun Jun 29, 2003 1:44 pm

Yes, the program counter points 2 instructions ahead because of the ARM7's three-stage pipeline; it's always 2 whole instructions in whichever the current instruction set is (pipeline is flushed when you switch instruction set).

Torne