0

I'm looking at a piece of assembly code and I'm stuck trying to make sense of something:

incl (%ebx, %eax, 4)

What exactly does this do? I tried plugging it into a .s file and compiling then watching registers in GDB but when it passes the instruction after I set ebx to an address and eax to 1 it changed nothing... I'm guessing I don't understand how to use it properly. Can anyone help?

nrz
  • 10,435
  • 4
  • 39
  • 71
Riptyde4
  • 5,134
  • 8
  • 30
  • 57

2 Answers2

2

It isn't incrementing a register; it is incrementing a memory location computed from the contents of the registers in the the instruction.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • how is it computed? and what if it was: incl %ebx, %eax, 4 – Riptyde4 Nov 07 '13 at 03:19
  • That basically means "increment the dword at address `%ebx + %eax * 4`". There's plenty of material explaining this, search for "x86 addressing modes". – gsg Nov 07 '13 at 03:36
0

I would suggest to not use GAS and AT&T syntax. It is especially invented in order to obfuscate the syntax and to make it unclear and unattractive for the beginners.

This syntax is created to be used by a back-ends for the HLL compilers. Human written programming with it is a masochism.

Even I (with 25 years of assembly programming background) hardly can recognize the normal instruction:

    inc dword [ebx+4*eax] 
; increment a double word at memory address (ebx+4*eax)

Use FASM instead. It has clear, human-centric syntax, best for hand written assembly programs.

johnfound
  • 6,857
  • 4
  • 31
  • 60
  • My computer architecture class strictly revolves around using AT&T/GAS, I'm just trying to work with what I have. The goal of the class is to teach C but at the same time learn what exactly the compiler is doing to make our code work. Thanks for the help. – Riptyde4 Nov 07 '13 at 23:31