Assembly Language Integer registers

坚强是说给别人听的谎言 提交于 2019-12-11 06:57:01

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9458537/assembly-language-integer-registers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!