Assembling ARM Instructions

Discussion in 'GBA - Hardware, Devices and Utilities' started by Blazer, Dec 30, 2009.

  1. Blazer

    Blazer GBAtemp Regular

    Aug 10, 2008
    United States
    I have a bunch of instructions here, presumably they are arm instructions, but I need a little help on assembling them and then 'applying' them to a ROM.

    It's an assembly hack. Here are the actual instructions:

    push {lr}ÂÂ @
    @-------------------------------@Get uses/equipped weapon of unit pointed at by r0
    lsl r0, r0, #0x18 @
    lsr r0, r0, #0x18 @
    ldr r1,ÂÂ ITEM_TABLE_REF
    ldr r1, [r1]ÂÂ@r1 points to item table
    mov r2, r0ÂÂ@
    lsl r0, r0, #0x03 @
    add r0, r0, r2 @
    lsl r0, r0, #0x02 @
    add r0, r0, r1 @Indexing of item table complete
    ldrb r0, [r0, #0x08] @
    mov r1, #0x02ÂÂ@"Use magic animation?"
    and r0, r1ÂÂ@
    lsr r0, r0, #0x01 @r0 == 1 or 0, guaranteed
    pop {pc}ÂÂ @

    I have a feeling ITEM_TABLE_REF is a variable (an offset to some data) that is supposed to be defined by some other code somewhere else or something... for the sake of testing things how would I go about just replacing this with a permanent offset (say 0x8B90000).

    I have DevKit Advance, read the entire website, and downloaded some form of GCC, but I'm not sure how to piece things together and actually assemble it.

    If no one's willing/able to tutor me or bring me up with an understandable guide on how to assemble the instructions and then complete the assembly hack, then if someone could do it for me (the game is Fire Emblem 7 (U) #1235) I'd appreciate that too.

    P.S. the hack is for a friend of mine... lol.
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    Nov 21, 2005
    I am slightly unsure as to what you want done:
    Do you want an IPS patch with the above hack in it to simply apply to the ROM?
    Do you want the instructions to do the above up to the making an IPS patch stage?
    Do you want a rundown of the hack? This is difficult without reverse engineering the hack: that hack is the last stage of it all from what I can see and I have no idea what is already in the registers and memory as well as the formats of the hack/data layout although I am guessing nothing "new" is being done here. Not to mention what you have there looks like a "simple" branch redirection hack as there is little prep work done (only the link register is popped) where most truly simple "cheat" hacks will pop everything (or enough to get things done) and then push it all back at the end of the "cheat".

    Unfortunately there are about 5* different assemblers in common rotation among GBA hackers all with slightly different takes on ARM assembly (more specifically their instruction layout (is it mov source, destination or mov destination, source), what operators (what signals a comment, hexadecimal, decimal, binary and what shorthand exists) and the like.
    As for what you have there everything I see there can be done within THUMB limitations and indeed the instruction names would seem to indicate it is done in THUMB mode (as an aside if you have not met it yet many modern ARM processors (including the ARM7TDMI of the GBA) have two operating modes known as ARM and THUMB, ARM is as you would expect with a set of fairly simple (reduced) 32 bit instructions while THUMB is a 32 bit "mode" but instructions are all 16 bit and there are a few limitations like only r0 to r7 being available for most instructions. is the document of choice for most hackers.
    By and large good hackers will use thumb mode unless it is truly necessary (usually to lessen impact of their additional code) but there are bad ones, new ones (who have only read the basic manual), lazy ones, those who need a quick hack (assembly across computing is known for being cumbersome to deal with in terms of memory and generally being fiddly and THUMB is even worse) and those whose reasoning I can not fathom. It goes without saying (but I will anyway) but once you are playing in these realms rules of thumb become significantly less useful.

    The big two when it comes to actual assembly though are probably goldroad (not held in high regard among programmers for a reason: legacy hacks and those who do not know other assemblers are the main users here) and the one that comes with devkitarm (I have heard of people using the old toolchains but I doubt it applies here) and alas I do not know/remember any of them well enough to pick it out of that snippet you have there.

    *goldroad, devkitarm's, no$gba's, VBA's (VBA-H-SDL is probably the beginning hacker's assembly grade emulator) and whatever the Chinese are using these days (it seems to vary), IDA if you are using that is usually a variation on one of the ones I have just mentioned.
    A few people (most notably some of the high end emulator authors) have branched into the ARM SDK assembler which costs a fortune but is very good (a cut above anything that exists in homebrew world before you even touch the IDE itself), unless you want to edit those apps you can ignore it.

    My little aside over what you have there looks to be everything you need provided you can get it assembled (your main/most likely problem will be if "@" does not signal a comment in your assembler of choice).
    As for "ITEM_TABLE_REF" you called it how I would but the key is in the colon (I too am not sure why it was done this way as it is only done once in the hack that you have there and it could just as easily be commented about)

    .long 0x08016060

    .long just signifies that it is a long rather than a short

    Ironically (we used to/usually suggest novice assembly programmers/hackers looking at the DS look at/learn about the GBA first) for devkitpro I am going to have to suggest and the guide there. In terms of cheat making there are better methods (the author himself will tell you as such) but it pulls it all together very well and should be what you want here.

    Edit: I sense this thread belongs in the GBA rom hacking section as well. I will leave that to you to sort with the mods though.