I created a very simple assembly program that prints the letter 'a' in DOS. I opened it in a hex editor and the result was this:
Assembly code:
mov ah, 2
mov dx, 'a'
int 21h
Hex code
B4 02 B2 61 CD 21
I wanted to understand how it was generated! Like, I do not know if I'm right, but I realized that:
B4 = mov ah
02 = 2
B2 = mov dx
61 = 'a'
CD = int
21h = 21
The 02
, 61
and 21
I understood what turned but and B4
, B2
and CD
?
Opcodes are decimal and not hex.
Opcode definition A complete machine language instruction consists of an opcode and zero or more operands with which the specified operation is performed. Examples are “add memory location A to memory location B,” or “store the number five in memory location C.” “Add” and “Store” are the opcodes in these examples.
In computing, an opcode (abbreviated from operation code, also known as instruction machine code, instruction code, instruction syllable, instruction parcel or opstring) is the portion of a machine language instruction that specifies the operation to be performed.
The opcode is the instruction that is executed by the CPU and the operand is the data or memory location used to execute that instruction.
Here's a nice reference: http://ref.x86asm.net/coder32.html
As you can see:
CD
is the opcode for int
B0+reg
is the opcode for mov reg, imm8
, where reg
is the destination register and as you can see from this table, ah = 100b
and dx = 010b
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