-1

These are the two line of assembler code.

0x0000000000400e8e <+34>: mov -0x8(%rbx),%eax
0x0000000000400e91 <+37>: add -0x4(%rbx),%eax

The following is the whole assembler code and the printed register, where the arrow on the left indicates the location that the code is currently stepped on:

 Dump of assembler code for function phase_2:
   0x0000000000400e6c <+0>:     push   %rbp
   0x0000000000400e6d <+1>:     push   %rbx
   0x0000000000400e6e <+2>:     sub    $0x28,%rsp
   0x0000000000400e72 <+6>:     mov    %rsp,%rsi
   0x0000000000400e75 <+9>:     callq  0x401391 <read_six_numbers>
   0x0000000000400e7a <+14>:    cmpl   $0x0,(%rsp)
   0x0000000000400e7e <+18>:    jne    0x400e87 <phase_2+27>
   0x0000000000400e80 <+20>:    cmpl   $0x1,0x4(%rsp)
   0x0000000000400e85 <+25>:    je     0x400ea8 <phase_2+60>
   0x0000000000400e87 <+27>:    callq  0x40136f <explode_bomb>
   0x0000000000400e8c <+32>:    jmp    0x400ea8 <phase_2+60>
=> 0x0000000000400e8e <+34>:    mov    -0x8(%rbx),%eax
   0x0000000000400e91 <+37>:    add    -0x4(%rbx),%eax
   0x0000000000400e94 <+40>:    cmp    %eax,(%rbx)
   0x0000000000400e96 <+42>:    je     0x400e9d <phase_2+49>
   0x0000000000400e98 <+44>:    callq  0x40136f <explode_bomb>
   0x0000000000400e9d <+49>:    add    $0x4,%rbx
   0x0000000000400ea1 <+53>:    cmp    %rbp,%rbx
   0x0000000000400ea4 <+56>:    jne    0x400e8e <phase_2+34>
   0x0000000000400ea6 <+58>:    jmp    0x400eb4 <phase_2+72>
   0x0000000000400ea8 <+60>:    lea    0x8(%rsp),%rbx
   0x0000000000400ead <+65>:    lea    0x18(%rsp),%rbp
   0x0000000000400eb2 <+70>:    jmp    0x400e8e <phase_2+34>
   0x0000000000400eb4 <+72>:    add    $0x28,%rsp
   0x0000000000400eb8 <+76>:    pop    %rbx
   0x0000000000400eb9 <+77>:    pop    %rbp
   0x0000000000400eba <+78>:    retq
 End of assembler dump.

This is the screenshot for the register.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Notice the `lea 0x8(%rsp),%rbx` that runs before those load+add instructions can be reached. So it's just getting a pointer to an array on the stack, for a pointer-increment loop over that array. Can you be more specific, e.g. anything you *do* understand but don't see how these instructions fit into it? Otherwise just read a manual on how AT&T syntax works, and what mov and add do, and single-step the asm with GDB which you're already using. – Peter Cordes Apr 25 '21 at 04:56

1 Answers1

1

That is the AT&T syntax for assembly.

The mov instruction has the general syntax:

mov source, dest

% is used as a prefix for registers, to distinguish from a symbol/label of the same name1.

Also, (%reg) means accessing the memory with the value of the contents of the register reg.

Also, something like -0x8(%rbx) means the content of the memory at the address obtained by subtracting 8 from the value in the rbx register.

Hence, the first instruction means move the contents of memory at the address [rbx - 8] to the register eax.

On similar lines, the add instruction means, add the contents of the memory at the address [rbx - 4] to the register eax.


Footnote 1: For example, mov %eax, eax is a store of the EAX register contents to the C global variable int eax, using an absolute addressing mode. Normally in 64-bit code you'd use mov %eax, varname(%rip) for static storage, but absolute addressing is possible, and the only option for directly using a symbol address in 32-bit code.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zoso
  • 3,273
  • 1
  • 16
  • 27