• 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] Current HP Check

Lance Koijer 2.0

Lance Koijer
105
Posts
6
Years
  • Hello guys..

    I am trying to code an ASM that checks if the current HP is lower or equal to the Half of the 1st Party Pokémon's Total HP.

    I have thought how to get the half in an ASM but the problem I have encountered is the byte indicator is not writing in the loaded address..

    here's the code:
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    
    main:
    	push {r0-r3, lr}
    	ldr r0, =(0x20242Dc) @loads the Total HP
    	ldrb r0, [r0]
    	ldr r1, =(0x20242Da) @loads the current hp
    	ldrb r1, [r1]
    	mov r2, #0x5 @multiplies to 5 to get the half 
    	mul r0, r2, r0 @gets the half of Total HP
    	mov r3, #0xA @moves one decimal to current HP
    	mul r1, r3, r1 @gets the value of Current HP
    	cmp r1, r0 @compares if Current HP is higher than Half of the total HP
    	bhi push2
    	ldr r1, =(0x203c1b4) @freespace
    	mov r0, #0x1
    	strb r1, [r0]	 @stores byte 1 to indicate that the Current HP is lower than or equal the half of total HP
    	pop {r0-r3, pc}	
    
    
    push2:
    	ldr r1, =(0x203c1b4)
    	mov r0, #0x0
    	strb r1, [r0] @stores byte 0 to indicate that the Current HP is higher than the half of total HP
    	pop {r0-r3, pc}

    it feels to me that it's either the storing of the byte or the branch checking makes the code not functioning. If someone can help me fix this, it is much appreciated. Thanks.
     
    88
    Posts
    7
    Years
    • Seen Jan 16, 2020
    Hello guys..

    I am trying to code an ASM that checks if the current HP is lower or equal to the Half of the 1st Party Pokémon's Total HP.

    I have thought how to get the half in an ASM but the problem I have encountered is the byte indicator is not writing in the loaded address..

    here's the code:
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    
    main:
    	push {r0-r3, lr}
    	ldr r0, =(0x20242Dc) @loads the Total HP
    	ldrb r0, [r0]
    	ldr r1, =(0x20242Da) @loads the current hp
    	ldrb r1, [r1]
    	mov r2, #0x5 @multiplies to 5 to get the half 
    	mul r0, r2, r0 @gets the half of Total HP
    	mov r3, #0xA @moves one decimal to current HP
    	mul r1, r3, r1 @gets the value of Current HP
    	cmp r1, r0 @compares if Current HP is higher than Half of the total HP
    	bhi push2
    	ldr r1, =(0x203c1b4) @freespace
    	mov r0, #0x1
    	strb r1, [r0]	 @stores byte 1 to indicate that the Current HP is lower than or equal the half of total HP
    	pop {r0-r3, pc}	
    
    
    push2:
    	ldr r1, =(0x203c1b4)
    	mov r0, #0x0
    	strb r1, [r0] @stores byte 0 to indicate that the Current HP is higher than the half of total HP
    	pop {r0-r3, pc}

    it feels to me that it's either the storing of the byte or the branch checking makes the code not functioning. If someone can help me fix this, it is much appreciated. Thanks.

    A couple notes:
    - The current/total HP are halfwords (2 bytes), so you should be using ldrh
    - you should use a right shift to divide by 2 (lsr rX, rX, #0x1)
    - you're storing r1 into r0. So you are storing the address into address 0x0 or 0x1. You should do strb r0, [r1] to store the value of r0 into the address of r1
    - EDIT: and rather than using some free ram, you might want to store into a temporary variable such as the lastresult variable at 0x020370d0

    Hope this helps :)
     
    Last edited:

    Lance Koijer 2.0

    Lance Koijer
    105
    Posts
    6
    Years
  • A couple notes:
    - The current/total HP are halfwords (2 bytes), so you should be using ldrh
    - you should use a right shift to divide by 2 (lsr rX, rX, #0x1)
    - you're storing r1 into r0. So you are storing the address into address 0x0 or 0x1. You should do strb r0, [r1] to store the value of r0 into the address of r1
    - EDIT: and rather than using some free ram, you might want to store into a temporary variable such as the lastresult variable at 0x020370d0

    Hope this helps :)

    Thanks for the response. Very.

    I'll gonna try that.
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • Well, that's the most complicated solution to checking if a number is double. I'd optimize that portion of it, and also generalize this into an easy to call function.

    push {lr}
    mov r3, #100
    mul r3, r3, r0
    ldr r0, totalhp
    add r0, r0, r3
    ldrh r1, [r0, #2]
    ldrh r0, [r0]

    do calc

    This would require a small wrapper to call it from a script properly, but it'd be worth it to get rid of the hard coded portions.
     

    Lance Koijer 2.0

    Lance Koijer
    105
    Posts
    6
    Years
  • Well, that?s the most complicated solution to checking if a number is double. I?d optimize that portion of it, and also generalize this into an easy to call function.



    This would require a small wrapper to call it from a script properly, but it?d be worth it to get rid of the hard coded portions.

    Sweet. Thanks for this.
     
    Back
    Top