I don't understand what this assembly instruction does. What is its effect and why?
imull $16, (%eax, %edx,4)
The initial values of the registers are
%eax= 0x100x
%edx= 0x3
I don't understand what this assembly instruction does. What is its effect and why?
imull $16, (%eax, %edx,4)
The initial values of the registers are
%eax= 0x100x
%edx= 0x3
I'm assuming you're trying to understand how to interpret that AT&T style assembly instruction, in particular the addressing part. I'm sure you don't need help understanding what the imull $16
part does - it simply performs a signed multiplication, the last l
standing for long
word.
(%eax, %edx, 4)
is a form of addressing, where you have a base address, an offset of a certain amount of elements, and a scale/multiplier for multiplying the number of elements by the size of each one: (base, offset, offset scale/multiplier)
.
What you end up with is (base + (offset * multiplier)
, so in this case it'll be:
(%eax + (%edx * 4))
(0x100 + (0x3 * 4))
(0x100 + 0xC)
(0x10C)
Therefore the instruction imull $16, (%eax, %edx,4)
performs a signed multiplication of 16
by the value of the long word at the address 0x10C
.
The result of this instruction will be whatever dword
is stored at the address 0x10c
multiplied by 16 (or, if you prefer, shifted to the left by 4 bits). The result will be written to that address as well.