• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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] Trying to learn Assembly

  • 2
    Posts
    7
    Years
    • Seen Apr 13, 2018
    I'm trying to learn ASM to help my brother in his hack, I tried to do a simple routine that would act like a "copy half-word into variable 0x800D at (pointer + 0x800D)"
    The objective of this is to help him on scripting.
    After reading some tutorials and trying to understand working routines I simply don't get why this didn't work, I'm sorry if this look idiot, but is better than don't asking.

    .align 2
    .thumb

    main:
    push {r0-r1,lr}
    ldr r0, .pointer
    ldr r1, .var
    add r0, r0, r1
    ldrh r0, [r0]
    strh r0, [r1]
    pop {r0-r1,pc}

    .align 2
    .pointer:
    .word 0x020270B6 + (0x8004 * 2)
    .var:
    .word 0x020270B6 + (0x800D * 2)

    You would store the pointer in variables 0x8004 and 0x8005, and then set variable 0x800D to a valor that would be added to the pointer in 0x8004 and 0x8005, after this, the routine would take the half-word in pointer2 (0x8004 0x8005 + 0x800D) and store it in 0x800D.
    But the game simply crash, I'm putting +1 in the callasm.
     
    I'm trying to learn ASM to help my brother in his hack, I tried to do a simple routine that would act like a "copy half-word into variable 0x800D at (pointer + 0x800D)"
    The objective of this is to help him on scripting.
    After reading some tutorials and trying to understand working routines I simply don't get why this didn't work, I'm sorry if this look idiot, but is better than don't asking.

    .align 2
    .thumb

    main:
    push {r0-r1,lr}
    ldr r0, .pointer
    ldr r1, .var
    add r0, r0, r1
    ldrh r0, [r0]
    strh r0, [r1]
    pop {r0-r1,pc}

    .align 2
    .pointer:
    .word 0x020270B6 + (0x8004 * 2)
    .var:
    .word 0x020270B6 + (0x800D * 2)

    You would store the pointer in variables 0x8004 and 0x8005, and then set variable 0x800D to a valor that would be added to the pointer in 0x8004 and 0x8005, after this, the routine would take the half-word in pointer2 (0x8004 0x8005 + 0x800D) and store it in 0x800D.
    But the game simply crash, I'm putting +1 in the callasm.

    You're confusing what a pointer is and what a value is. A pointer, in this context, is going to be an address which contains the value of vars 0x8004, 0x8005 respectively. What you want to do is dereference them (get the value at the pointer) and store the sum in var 0x800D.


    .align 2
    .thumb

    main:
    ldr r0, var_8004
    ldr r1, var_8005
    ldr r2, var_800D

    ldrh r0, [r0]
    ldrh r1, [r1]
    add r0, r0, r1

    strh r2, [r0]
    bx lr

    .align 2
    var_8004:
    .word 0x020370C0

    var_8005:
    .word 0x020370C2

    var_800D:
    .word 0x020370D0

    Obviously the above is not written for optimization, but clarity.
     
    You're confusing what a pointer is and what a value is. A pointer, in this context, is going to be an address which contains the value of vars 0x8004, 0x8005 respectively. What you want to do is dereference them (get the value at the pointer) and store the sum in var 0x800D.


    .align 2
    .thumb

    main:
    ldr r0, var_8004
    ldr r1, var_8005
    ldr r2, var_800D

    ldrh r0, [r0]
    ldrh r1, [r1]
    add r0, r0, r1

    strh r2, [r0]
    bx lr

    .align 2
    var_8004:
    .word 0x020370C0

    var_8005:
    .word 0x020370C2

    var_800D:
    .word 0x020370D0

    Obviously the above is not written for optimization, but clarity.

    Thanks for helping me, I managed to get this result in the end:

    .align 2
    .thumb

    main:
    push {r0-r1,lr}
    ldr r0, .pointer
    ldr r0, [r0]
    ldr r1, .var
    ldrh r1, [r1]
    add r0, r0, r1
    ldr r1, .varend
    ldr r0, [r0]
    strb r0, [r1]
    pop {r0-r1,pc}

    .align 2
    .pointer:
    .word 0x020370C0
    .varend:
    .word 0x020370D0
    .var:
    .word 0x020370BE
     
    Back
    Top