Hello there.
Im working on my simple assembler. Im looking to Intel and AMD documentations;
ADC AL, imm8 : 14 ib
ADC AX, imm16 : 15 iw
ADC EAX, imm32 : 15 id
Im writing a code like that in NASM,
[BITS 32]
ADC al, 0x40
ADC ax, 0x4040
ADC eax, 0x40404040
and looking to machine codes are,
14 40 66 15 40 40 15 40 40 40 40
As you see for AL and EAX, machine codes are true but for AX, there is an extra code: 66
Also i used same code in Delphi. And disassemblied. Same result.
What is wrong? Are the documents wrong? Or compilers are wrong?
(Also this is same in ADD instruction)
Thanks in advance.
ADC Instruction Machine Code
Re: ADC Instruction Machine Code
iirc (and that's a big *if*), 0x66 is an instruction operand size prefix that tells the CPU that the next instruction will be a word (or maybe, dword) value.
Website: https://joscor.com
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
Re: ADC Instruction Machine Code
It's covered in the 80386's programmers reference manual, in section 16.2 which starts on the end of page 232.
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: ADC Instruction Machine Code
Code: Select all
ADC AX, imm16 : 15 iw
ADC EAX, imm32 : 15 id
To save you from a big list of opcodes, all word (16-bit), doubleword (32-bit), and quadword (64-bit) versions of one instruction map to the same opcode byte. The current operating mode determines which version is used when the processor sees that opcode. To still be able to use shorter sizes, you must add extra information (a prefix) to do something other than its default behaviour.
0x66 is the operand size prefix - it tells the processor to toggle between 16-bit and 32-bit register sizes for the next instruction.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: ADC Instruction Machine Code
Note that it doesn't affect opcode 14h (ADC AL,imm8) because it doesn't share an opcode with another ADC instruction.
OT: Oooh, shiny, old intel manual!
OT: Oooh, shiny, old intel manual!
Re: ADC Instruction Machine Code
Just about every instruction except for ones involving segment registers requires a operand prefix to access the 16bit registers from a 32bit environment. Although iirc there aren't any instructions that require a operand prefix to access 8bit registers.