• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] Trouble with an ASM routine

  • 9
    Posts
    4
    Years
    • Seen Dec 15, 2021
    Hi guys

    I've started to study asm, so I decided to try to create some routines as training, but I bumped into a problem:

    The purpose of this routine is to heal every pokémon that is not fainted (so their hp must be different from 0, useful for things such as nuzlocke challenge ROM).
    The routine iterates every pokémon in the party, until it finds a pokemon with level equal to 0 (because that's impossible so the party is over) and then quit

    The Flow-Chart is the following:
    Spoiler:


    The code is the following:
    Spoiler:


    Code explanation:
    Spoiler:


    I execute the routine in Littleroot town sign placed at position (000F;000D):
    Spoiler:


    I know that that routine is not the best way to handle only-one-dead-rule in a nuzlocke rom (because I should remove all healing items, change all pkmn center script and then it wouldn't work anyway because of healing-box), but this is only an exercise.

    I'm not 100% sure,but the offset should be right.

    So I have some questions:

    1) Why does the game restart when I talk to the sign?
    2) Can I use thumb set instead of arm set? The compiler told me that "Thumb does not support conditional execution", but I saw that on this forum someone using conditional branches with thumb.


    Thanks for all

    -JapaBijou
     

    Attachments

    • [PokeCommunity.com] Trouble with an ASM routine
      fewigtjre.PNG
      29.6 KB · Views: 6
    If you just want to just hack the gen3 games, you might find using the decompilations easier than assembly.
    For example, in pokeemerald you could do this simply with:
    Code:
    int i;
    for(i = 0; i < gPlayerPartyCount; i++){
    	if(gPlayerParty[i].hp != 0) gPlayerParty[i].hp = gPlayerParty[i].maxHP;
    }


    But to actually answer your questions:
    1) The game crashes because the processor is still in ARM-mode when you return to the game's thumb code by popping pc.
    You should either just use thumb code or to return with the bx instruction, which can change the processor mode.

    2) You're trying to use branch-with-link (BL) with conditions, which is not allowed in thumb mode, instead you should be using the branch instruction (B).
    also you're using ldrb for loading single-byte constants like total_HP_offset, which is also not allowed, use mov instead.
     
    If you just want to just hack the gen3 games, you might find using the decompilations easier than assembly.
    For example, in pokeemerald you could do this simply with:
    int i;
    for(i = 0; i < gPlayerPartyCount; i++){
    if(gPlayerParty.hp != 0) gPlayerParty.hp = gPlayerParty.maxHP;
    }



    How can I do that?

    But to actually answer your questions:
    1) The game crashes because the processor is still in ARM-mode when you return to the game's thumb code by popping pc.
    You should either just use thumb code or to return with the bx instruction, which can change the processor mode.

    2) You're trying to use branch-with-link (BL) with conditions, which is not allowed in thumb mode, instead you should be using the branch instruction (B).
    also you're using ldrb for loading single-byte constants like total_HP_offset, which is also not allowed, use mov instead.

    I managed to switch to thumb using b instead of bl. What is the difference between those two?
    Anyway, I changed the code:

    Spoiler:


    But compiler give me this error:

    D:\..\temp.asm: 16: Error: cannot represent THUMB_IMM relocation in this object file format
    D:\..\temp.asm: 25: Error: cannot represent THUMB_IMM relocation in this object file format
    D:\..\temp.asm: 36: Error: cannot represent THUMB_IMM relocation in this object file format
    D:\..\temp.asm: 40: Error: cannot represent THUMB_IMM relocation in this object file format

    What that mean?

    Thanks again

    EDIT:

    I removed r1 and add offsets in this way:
    Spoiler:


    Now it compiles and game doesn't reset but doesn't heal my team.
    Why?
     
    Last edited:
    Oh it worked!

    I should work slower in order to avoid those careless mistakes

    Thanks for all
     
    Back
    Top