0

In intel assembly 86-84 (AT&T) what's the difference between:

imul $4, a, %eax

and:

imul $4, $a, %eax

and:

imul $4, (a), %eax # Sometimes I see braces around registers too, what is their job?

where a is a variable in memory declared like this:

.section .data 
a: .int 0x2
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Have you tried reading the GNU as manual? It has a brief introduction to the syntax. – fuz Apr 06 '21 at 09:29
  • I read but still I am confused between the three I am not settled on this one –  Apr 06 '21 at 10:08
  • 1
    `$a` is an immediate, absence of the `$` indicates a memory operand. Registers in parentheses indicate index registers. – fuz Apr 06 '21 at 10:13
  • what if it is $garbage_address? –  Apr 06 '21 at 14:16
  • I don't understand what you mean. That would still be an immediate. – fuz Apr 06 '21 at 14:42
  • `imul $4, $a, %eax` is an error; IMUL can't take two immediate operands. Do `mov $a * 4, %eax` to do math at assemble time, but that only works if `a` is a .equ constant, not a label, because the assembler + linker don't support multiplying an address by 4. – Peter Cordes Apr 06 '21 at 16:29
  • @fuz you are wrong, it's the pointer to it –  Apr 06 '21 at 21:09
  • @john The addressing mode is “immediate” as in “the operand is this value.” – fuz Apr 06 '21 at 21:25

0 Answers0