I want to make Assembly compiler. To do that, I should make research about Assembly opcodes, so I found this on the Web. When I test to compile some codes with NASM, like this:
add eax, eax
It outputs this on Binary:
6601C0
However, when I see the reference of Assembly Opcodes, it displays this screen:
Where ADD opcode is 00, 01, 02, 03, 04, 05. Which opcode is right? Can I use all of them, or should I use 01 (based on binary compiled with NASM).
What you found is just some reference that someone on the Internet put together. The authoritative reference comes from Intel and can be downloaded here: Intel® 64 and IA-32 Architectures Software Developer Manuals.
You obviously assembled the code for a 16-bit real-mode environment (like DOS), where it was assembled to 66
01
C0
.
Look at the first byte 66
. This is called by Intel "operand-size override prefix" and in your reference "OPSIZE". It changes the size of the operands from 16-bit to 32-bit (AX
to EAX
). That is why I guess the environment is a 16-bit system.
The second byte 01
is the ADD
instruction in your reference on the second place in the first line. Your reference calls it ADD Ev Gv
. The Intel manual calls it ADD r/m16, r16
. With the operand-size override prefix you can read it as ADD r/m32, r32
.
The third byte C0
is the "Ev Gv" in your reference (Intel: "r/m32, r32"). Intel calls it "ModR/M" byte. Some bits in this byte define the target("Ev"), some bits define the source ("Gv"). Look at the table "Table 2-1. 16-Bit Addressing Forms with the ModR/M Byte" in the Intel manual.
To answer your question: No, you have to use the specific ADD
instruction for the specific purpose. The ADD
instructions perform different operations.
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