The unknown syntax for the "imul" instruction in x86 assembly

I wrote a very basic C function called "multby22" that does exactly what its name implies: it takes a lot of time and returns that it multiplies by 22 for a long time. (I know this is a meaningless function, but I wrote it try and help me with x86 build.) So:

long multby22(long x) { return 22 * x; } 

When I ran the program and ran "objdump" in the executable, I found the disassembled code for "multby22" as follows:

 080483ff <multby22>: 80483ff: 55 push %ebp 8048400: 89 e5 mov %esp,%ebp // Create the stack frame. 8048402: 8b 45 08 mov 0x8(%ebp),%eax // Grab the argument and put it into the %eax register. 8048405: 6b c0 16 imul $0x16,%eax,%eax // ??? 8048408: 5d pop %ebp // Pop the buffer pointer and return. 8048409: c3 ret 

I understand that "imul" is for integer multiplication, but I could not find anything that would help me with this syntax! The closest I found:

 imul [reg] [reg] [const] 

... where the 2nd and 3rd arguments are multiplied together and then placed in the 1st argument, which should be a register. In the assembly that I generated, the first argument is a constant!

+4
source share
2 answers

You have found the correct instruction. The AT & T assembly syntax simply turns out to be the โ€œinverseโ€ of how everyone else does it. The destination register is on the right.

Your code multiplies EAX by 22 (0x16) and puts the result in EAX.

If you are trying to compare instructions with documentation, you should probably look into a disassembler that can output Intel syntax parsing.

+7
source

0x16 = 22 in decimal base. The compiler writes it in hexadecimal notation. Thus, the first will be multiplied by the second and will be saved in the third.

+1
source

All Articles