• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[ASM & Hex] Asm branch with link

82
Posts
6
Years
  • Will keep it short and sweet. Compiling a routine(half a routine) but the damn bl isnt linking to the right place. You can see on the right is my code and the left is the disassembled version in the emulator. Offset ending in 96 is equal to line 12. Doing it with labels spits out "FF F7 Fe FF".

    I also tried "bl 0x75C14".

    What the f*** am i doing wrong?!

    Secondly, can someone explain why sometimes the compiler says "branch out of range" for something like "bne 0x28b962"? Thank you!

    Asm branch with link
     

    Skeli

    Lord of the Rings
    300
    Posts
    10
    Years
  • You need to write the code like this:

    Code:
    ...
    ldrb r0, [r4]
    ldr r1, .loc
    bl Jump
    mov r1, #0x1
    ...
    
    Jump:
    bx r1

    The code is trying to branch from offset 0x0 to 0x75C14. Because of where you plan on inserting the routine (0x7A7990), the branch is too long and you need to branch like above ^. I recommend reading FBI's ASM tutorials for more info.
     
    82
    Posts
    6
    Years
  • You need to write the code like this:

    Code:
    ...
    ldrb r0, [r4]
    ldr r1, .loc
    bl Jump
    mov r1, #0x1
    ...
    
    Jump:
    bx r1

    The code is trying to branch from offset 0x0 to 0x75C14. Because of where you plan on inserting the routine (0x7A7990), the branch is too long and you need to branch like above ^. I recommend reading FBI's ASM tutorials for more info.

    How would I get it to branch to 75c14 then? I am half way through fbis tut. I started last night. I got about half way and then went to read Knizz's and SQ's. Any others you would recommend?

    I understand branching to labels. I see that all the time in move effects. But i specifically need to branch out of my asm code and back. Do I put the .org 7a7990 at the beginning so it's branching backwards from 7a7990 to 75c14?

    MRDS's loadorder rewrite(abilities resource -> prankster, Gale wings, quick feet and a few others) bl from 14cd8 to 9axxx(I can't remember exactly offset). So why can that routine branch out the routine? It's just "bl 0x9axxx"
     

    Skeli

    Lord of the Rings
    300
    Posts
    10
    Years
  • How would I get it to branch to 75c14 then? I am half way through fbis tut. I started last night. I got about half way and then went to read Knizz's and SQ's. Any others you would recommend?
    If you're getting into battle asm, you should take a look at JPAN's documentation: https://www.pokecommunity.com/showpost.php?p=7156541&postcount=5

    I understand branching to labels. I see that all the time in move effects. But i specifically need to branch out of my asm code and back. Do I put the .org 7a7990 at the beginning so it's branching backwards from 7a7990 to 75c14?
    If you branch to something using BL, when the routine you branched to is done, it'll automatically return to where you branched from. This works even if you branch to a label. Generally you would put a .org 0xwhatever at the top of your file if you wanted to branch directly, but the range 0x7A7990 to 0x75C14 is too far so your compiler will give you an error.

    MRDS's loadorder rewrite(abilities resource -> prankster, Gale wings, quick feet and a few others) bl from 14cd8 to 9axxx(I can't remember exactly offset). So why can that routine branch out the routine? It's just "bl 0x9axxx"
    0x14CD8 is relatively close to 0x9Axxx so that branch will work. I don't know specifically the max range you can branch to that way, but I think it's somewhere around 0x200000.
     
    Back
    Top