In reference guides I see that MOV
is opcodes 88, 89, 8A, ... etc.. Why are there multiple opcodes for one instruction?
"mov" is an instruction, encoded with the operation code or "opcode" 0xb8. Since mov takes an argument, the next 4 bytes are the constant to move into eax. The opcode 0xb9 moves a constant into ecx. 0xba moves a constant into edx.
a) What is the minimum number of bits required to represent the OPCODE? There are 255 OPCODES and each requires a unique pattern. Therefore, we need ceil(log2255) = 8 bits.
Opcodes and operands 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.
; print a byte to stdout mov eax, 4 ; the system interprets 4 as "write" mov ebx, 1 ; standard output (print to terminal) mov ecx, variable ; pointer to the value being passed mov edx, 1 ; length of output (in bytes) int 0x80 ; call the kernel.
That is because those instructions are slightly different from the CPU point of view. Although mnemonic is the same, operands are different. For example in this reference, the instruction column clearly shows the difference between those opcodes.
They are for different type of sources and destinations. To the CPU there is so much difference between moving 8 and 16/32 bit values to and from registries and memory locations that it is encoded as different opcodes.
List of opcodes.
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