Any idea what this assembly code is doing?

Discussion in 'Computer Programming, Emulation, and Game Modding' started by StackMasher, Jul 13, 2017.

  1. StackMasher
    OP

    StackMasher GBAtemp Regular

    Member
    102
    49
    Nov 29, 2016
    I'm tired of failing all my programming projects and want to try something new. So I decided to try some reverse engineering. Currently I'm working on the linux version of saints row 4, and I'm stuck on this part (parts cut out, ask if more info needed):
    Code:
    1000a3b0:   e8 0b cf ff ff           call   100072c0 <SteamAPI_RestartAppIfNecessary@plt> #Checks if steam is open, launches it if not and returns 1 indicating that the app should be closed as steam will reopen it. Returns 0 if the app can continue
    1000a3b5:   84 c0                   test   %al,%al # ???
    1000a3b7:   0f 85 81 01 00 00       jne    1000a53e <__isinff@plt+0x197e>
    From looking around, it seems like this code tests if %al is 0, and jumps if not. But why %al? I'm not super familiar with 32bit x86 calling conventions but according to wikipedia, return codes are passed in %eax
     
  2. tetrabrik

    tetrabrik Advanced Member

    Newcomer
    63
    25
    Sunday
    United States
    yes it does seem it's testing the al part of the eax register. this would be the lower 8 bits of the eax. eax is composed of: ax (16 bits) ah (8 bits) and al (8 bits). they can be used as one register of 32 bits (eax) or just parts of it (as in this case, al only 8 bits).
    my guess is that you're correct, the value represents a boolean inside a conditional statement.
    without more context not sure where that value's coming from.
     
  3. Mikemk

    Mikemk GBAtemp Maniac

    Member
    1,483
    517
    Mar 26, 2015
    United States
    Extending what tetrabrik said:

    All general registers and several other follow the same pattern.

    In the early days of 8-bit computers, you had registers a, b, c, and d. When 16 bit came around, it kept 8 bit access to each half to make porting old code easier.
    32-bit and 64-bit CPUs are backwards compatible, so they still have access. r*x (where * is a/b/c/d) is the full 64-bit register, eax is the lower 32 bits, ax the lower 16 bits. al and ah are the lower and higher half of ax.
     
  4. StackMasher
    OP

    StackMasher GBAtemp Regular

    Member
    102
    49
    Nov 29, 2016
    I figured this out ages ago but thanks
     
  5. Mikemk

    Mikemk GBAtemp Maniac

    Member
    1,483
    517
    Mar 26, 2015
    United States
    Also, you're probably seeing a compiler optimization, it's doubtful that the init code was written in assembly.

    — Posts automatically merged - Please don't double post! —

    Oh, sorry, didn't notice the date
     
  6. wolfmankurd

    wolfmankurd GBAtemp Regular

    Member
    154
    59
    Jul 20, 2013
    You just answered your own question.