1

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
1
  • 1
    How would I solve? I don't see a problem in the first place. Are you asking what would the result be?
    – Flexo
    Feb 27, 2012 at 0:04

2 Answers 2

9

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.

1

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.

2
  • how did you find the address to be 0x10c
    – Raj
    Feb 27, 2012 at 0:15
  • this wat i did 0x3 + 4= 0x7 then 0x7 + 0x100=? this where i am confused
    – Raj
    Feb 27, 2012 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.