• 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] Trouble with an ASM routine

9
Posts
3
Years
  • Age 21
  • 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

  • fewigtjre.PNG
    fewigtjre.PNG
    29.6 KB · Views: 5
438
Posts
6
Years
  • Age 37
  • Seen Apr 20, 2024
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.
 
9
Posts
3
Years
  • Age 21
  • Seen Dec 15, 2021
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:
438
Posts
6
Years
  • Age 37
  • Seen Apr 20, 2024
You can find a tutorial for setting up pokeemerald here: https://www.pokecommunity.com/showthread.php?t=426921

Your team doesn't get healed because your code is buggy:
- it jumps to finish when level is not 0
- it's reading the level a second time instead of hp
- It's accessing level as 4 bytes instead of 1
- it's using r1 even though you haven't set its value
...and maybe more.
 
Last edited:
9
Posts
3
Years
  • Age 21
  • Seen Dec 15, 2021
Oh it worked!

I should work slower in order to avoid those careless mistakes

Thanks for all
 
Back
Top