I am writing a disassembler and I was reviewing the instruction format (and doing some disassembling by hand) and I ran into an instruction that I can't seem to be able to decode.
The output for that particular instruction (from objdump) is:
c6 05 14 a0 04 08 01 movb $0x1,0x804a014
However, I dont understand how the instruction is decoded, since the opcode c6 is supposed to be MOV Eb Ib (Mod R/M to imm8).
Can somebody enlighten me as to how it is decoded?
Thanks!
This is explained (in part) by Alex Frunze's answer, but his is a bit terse, so I will provide some explantation here:
I hope this helps.
c6 - opcode (there's also a part of opcode in Mod/RM byte, in /digit(reg) field)
05 - Mod/RM byte (mod=00b, r/m=101b, /digit(reg)=0 - part of opcode)
14 a0 04 08 - disp32
01 - imm8
And it's a mov from Ib to Eb. You're probably confusing the AT&T syntax, in which objdump is showing the disassembly, with that of Intel/AMD documentation. The order of operands in AT&T syntax is the opposite of that in x86 CPU manuals.
Well, moving to an immediate doesn't mean anything. What that instruction does is move a constant 1 into the memory byte located at 0x804a014. Something like the equivalent C code:
*(unsigned char *)0x804a014 = 1;
You've got opcode c6, as you know. You can look that up as part of the MOV instruction in Volume 2A of the docs.
The 05 is the ModR/M byte. You can decipher that using Table 2-2 of volume 2A, "32-Bit Addressing Forms With the ModR/M Byte". Look for 05 in the "Value of ModR/M Byte (in Hexadecimal)" part of the chart. Trace left from there, and you'll see that the effective address for this ModR/M value is given in 'disp32' form. The footnote there says "The disp32 nomenclature denotes a 32-bit displacement that follows the ModR/M byte". In this case that's the next four bytes of your instruction: 14 a0 04 08.
Finally, you have the 8-bit immediate 01, and the complete instruction is decoded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With