Escolar Documentos
Profissional Documentos
Cultura Documentos
byte
7 6 5 4 3 2 1 0
opcode
mod
d w
reg
Opcode byte
r/m
[optional]
low disp
[optional]
high disp
[optional]
low data
[optional]
high data
This is the general instruction format used by the majority of 2-operand instructions
but some instructions have short form e.g. pop (special cases has no mod byte and
reg. is with opcode byte) some instruction can have more than form due to short
form bec. it is used so much and accumulator operand.
word/byte
mod
mode
reg
register
r/m
register/memory
Details on Fields
Opcode Byte
Opcode field specifies the operation performed (mov, xchg, etc).
d=0
one byte of immediate data is present which must be signextended to produce a 16-bit operand
s=0
data is word
W=0
data is byte
Addressing Mode Byte (Byte 2)
Reg
Bits 3-5
R/M
Bits 0-2
(register/memory)
MOD
At second line this is direct addressing mod = 00 & r/m = 110 and it must be followed
by two address bytes.
At mod = 01 disp is 8 bit signed (max ve is -128), at mod = 10 disp 16 bit unsigned.
Reg:
010 SS
[BP]
Doesnt this cause a problem?
What about MOV DL, [BP]?
No displacement, Mode 00
[BP] addressing mode, R/M 110 (used for direct addressing)
This actually assembles as MOV DL, [BP+0]
8-bit displacement, Mode 01
[BP] addressing mode, R/M 110
011 DS
Note that this makes [BP] move instructions at least three bytes long.
Addressing Mode Byte
In general is not present if instruction has no operands (i.e. no registers and memory
locations only disp or nothing e.g. JMP)
For one-operand instructions the R/M field indicates where the operand is to be found
(e.g. DIV instruction r/m indicates register/mem word or byte)
For two-operand instructions (except those with an immediate operand) one is a register
determined by REG (SREG) field and the other may be register or memory and is
determined by R/M field.
Direction bit has meaning only in two-operand instructions Indicates whether "destination" is
specified by REG or by R/M Note that this allows many instructions to be encoded in two
different ways.
SREG 000
ES
001 CS
010 SS
011 DS
Examples
MOV instruction has seven possible formats. We will not discuss them all.
MOV reg/mem,reg/mem
Disp1
Disp2
- if d = 1 then REG = dest (AX) 000 and R/M = source (BX) 011
= 1000 1011
EX: 2
MOV [BX+10h],CL
- w = 0 because we are dealing with a byte
- d = 0 because we need R/M Table to encode [BX+10h] therefore first byte is (1000
1000) = 88H
- Since 10H can be encoded as an 8-bit displacement, we can use MOD=01
REG=001(CL) and R/M=111(BX+Disp), so the second byte= 0100 1111 = 4FH and the
last byte is 10H
Result = 88 4F 10
Note: MOV [BX+10H],CX Result = 89 4F 10
- w = 1 because we are dealing with a byte
- d = 0 because we need R/M Table to encode [BX+10h] therefore first byte is (1000
1001) = 89H
- Since 10H can be encoded as an 8-bit displacement, we can use MOD=01
REG=001(CX) and R/M=111 (BX+Disp), so the second byte= 0100 1111 = 4FH and the
last byte is 10H
MOV immediate to reg/mem
1100 011w
disp1
disp2
Note special form for accumulator. Many other instructions have a short form for AX
register.
For Encoding you will use table D-2 in manual for different instruction format for each
instruction.
For Decoding: use table D-3 in manual for instruction decoding
For clock cycles taken for each instruction, it will be found in table D-2 in manual.