Things To Know : Instruction Format Instructions Can Have 1, 2 or No Operands
Things To Know : Instruction Format Instructions Can Have 1, 2 or No Operands
Things to know…
Instruction format opcode Operand(s)
HLT ; no operand
8086 Addressing Modes cse341 Instruction cannot have:
Dept. of Computer Science and Engineering SUB [DI], [1234h] ; memory locations as both operands
BRAC University
CSE 341 Team MOV 1234, AX ; immediate data as destination operand
Addressing modes of 8086 Microprocessor are categorized III. Register [direct] addressing
as: IV. Register indirect addressing
Addressing Data V. Base-plus-index addressing
Addressing Program codes in memory VI. Register relative addressing
Addressing Stack in memory VII. Base-relative-plus-index addressing
Addressing I/O
Implied addressing
CSE – 341: Microprocessors CSE – 341: Microprocessors
BRAC University BRAC University
7/9/2021
JMP 1000: 0000 data to and from stack (in particular from stack
JMP doagain ; doagain is a label in code segment).
PUSH AX
CALL 1000:0000 POP CX
CALL doagain ; doagain is a procedure in code
• CALL also uses the stack to hold the return
Often known as far jump or far call address for procedure.
CALL SUM ; SUM is a procedure name
CLC ; clear carry flag LOW BYTE DISPLACEMENT / DATA HIGH BYTE DISPLACEMENT / DATA
RET ; return to DOS LOW BYTE of IMMEDIATE DATA HIGH BYTE of IMMEDIATE DATA
E.g 32 ways to specify the source in MOV CX, source. You need to locate the codes appropriately.
MOV CX, source Most of the time this work will be done by assembler
a 16-bit register (8 in number)
If the expression for the effective address contains a displacement which is too
large to fit in 8 bits then out in 10 in MOD bits.
6 bits of
MOV, ADD etc
MOV 8B43H [SI], DH: Copy a byte from DH to memory with
OPCODE D W MOD REG R/M
16 bit displacement given the opcode for MOV=100010
D - direction BYTE 1 BYTE 2
If D=0, then direction is from a register (source)
If D=1, then direction is to a register (destination) 1 0 0 0 1 0 0 0 1 0
OPCODE D W MOD REG R/M
W - word
If W=0, then only a byte is being transferred (8 bits) Therefore D=0
If W=1, them a whole word is being transferred (16 bits) MODE OPERAND NATURE
source -- 8 bits (not a word size)
00 Memory with no displacement
MOV [SI + 8B43H] , DH Therefore W=0
MODE OPERAND NATURE 01 Memory with 8-bit displacement
• 34h here is an 8-bit displacement
00 Memory with no displacement MOV AX, [BX] 10 Memory with 16-bit displacement
• [BX+34h] is a memory/offset address
01 Memory with 8-bit displacement MOV AX, [BX + 12h] 11 Both are registers
10 Memory with 16-bit displacement MOV AX, [BX + 1234h]
MOV [BX + 34h ], AL
11 Both are registers MOV AX, BX BYTE 3 BYTE 4
1 0 0 0 1 0 0 0 1 0 1 1 0
• Value for R/M with corresponding MOD
value OPCODE D W MOD REG R/M
• Value for REG with corresponding W Check column that matches with MOD
value and the register considered in D value
MOV [SI + 8B43H] , DH
Example 1 Example 2
MOV 8B43H [SI], DH: Copy a byte from DH to memory with MOV AX, BX: given the opcode for MOV=100010
16 bit displacement given the opcode for MOV=100010
BYTE 1 BYTE 2
BYTE 1 BYTE 2
1 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0
1 0 0 0 1 0 1 1 1 1
OPCODE D W MOD REG R/M
OPCODE D W MOD REG R/M
Example 1 Example 2
MOV 8B43H [SI], DH: Copy a byte from DH to memory with MOV AX, BX: given the opcode for MOV=100010
16 bit displacement given the opcode for MOV=100010
BYTE 1 BYTE 2
BYTE 1 BYTE 2 1 0 0 0 1 0 1 1 1 1 0 0 0
1 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 OPCODE D W MOD REG R/M
OPCODE D W MOD REG R/M
MOV [SI + H] , DH
BYTE 3 BYTE 4
0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 1
LOW BYTE DISPLACEMENT HIGH BYTE DISPLACEMENT
Machine Code: 1000 1000 1011 0100 0100 0011 1000 10112 or 88 B4 43 8B16
CSE – 341: Microprocessors CSE – 341: Microprocessors
BRAC University BRAC University
7/9/2021
Example 2 Machine Code: 1000 1011 1100 00112 or 8B C316 Instruction Template
MOV AX, BX: given the opcode for MOV=100010 The Intel literature shows two different formats for coding
8086 instructions.
BYTE 1 BYTE 2
Instruction templates helps you to code the instruction
1 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1
properly.
OPCODE D W MOD REG R/M
Example:
IN AL, 05H
QUIZ Example
Compute the machine code for the following using the table below
and the opcode for MOV as100010
Example QUIZ
MOV 43H [SI], DH: Copy a byte from DH register to Compute the machine code for the following using the table below
memory location. and the opcode for MOV as100010
Example 3
MOV CX, [437AH]: Copy the contents of the two memory
locations to the register CX.