Chapter 4
Chapter 4
Chapter 4
COMPUTER
ARCHITECTURE
INTEL 8086/8088
1. Functional Diagram
2. Components
3. Instruction coding
4. 8086/8088 addressing modes
5. Instruction set
6. Pipeline
8086/8088 diagram
8088/8086 units
Bus Interface Unit
Controlize system bus:
• Look up address
• Fetch op-code from memory
• read/write data from/to memory or I/O
including:
• Adder
• CS, DS, SS, ES
• PC/IP
• Instruction Queue
• Bus controller
8088/8086 units
Execution Unit
EU receives op-code & data from BIU. Results are transferred
to memory or I/O.
units:
• ALU
• CU
• AX, BX, CX, DX, SP, BP, SI, DI
8086/8088 registers
General-purposed registers:
16 bits:
• AX: Accumulator (input operant and output)
• BX: Base (address)
• CX: Count (counting the loop)
• DX: Data
Can be splited into 8 bit registers: AH AL, BH, BL, CH, CL, DH, DL
8086/8088 registers
Pointer and indexing (16 bits):
SP (Stack Pointer): points to the top of stack
BP (Base Pointer): used with stack segments
SI (Source Index): for data movement
DI (Destination Index): for data movement
8086/8088 registers
CS (Code Segment): points to the segment containing the code
DS (Data Segment): points to the segment containing the data
SS (Stack Segment): points to the segment containing the stack
ES (Extra Segment): points to the segment containing the extra
data.
8086/8088 registers
Instruction pointer & Flag register:
IP (Instruction Pointer): so-called PC(Program Counter) containing
the address of the next instruction to be executed;
FR (Flag Register).
8086/8088 Flag register
8086/8088 registers
Status flags:
CF (Carry Flag): C=1 if carry; C=0otherwise
AF (Auxiliary Flag): AF=1 if carry between 3rd and 4th bit;
AF=0otherwise
PF (Parity Flag): PF=1 if sum of bit 1s is odd; PF=0 if sum of bit 1s is
even
OF (Overflow Flag): OF=1 if overflowed in results
ZF (Zero Flag): ZF=1 if the result equals to 0; ZF=0 otherwise
SF (Sign Flag): SF=1 if the result is negative; SF=0 otherwise
Control flags:
DF (Direction flag)
TF (Trap/Trace flag)
IF (Interrupt flag)
Instruction Queue
Containing op-code.
Speed-up.
Instruction set
What is an instruction?
A binary word
Stored in memory
Fetched by CPU to be executed
Each has it own operation
Execution stages:
IF: Instruction Fetch
ID: Instruction Decode
EX: Instruction Execution
MEM: Memory Access
WB: Write Back
Instruction
Two components: op-code and operants
length: 8, 16, 24, 32 and 64 bits.
8086/8088 instructions have lengths from 1 to 6 bytes
Opcode Operands
IN:
IN reg, <the address of input port>
Read an data item from the input port and assign to reg
Example: IN AL, 0F8H; AL (0F8h)
MOV DX, 02F8H
IN AL, DX; AL (DX)
Data movement
OUT:
OUT <the address of output port>, reg
Write an data item from reg to the output port.
Example: OUT 0F8H, AL; (0F8h) AL
MOV DX, 02F8H
OUT DX, AL; (DX) AL
Numerical computation
ADD:
ADD <dst>, <src>; dst dst +src
Example ADD AX, BX; AX AX + BX
ADD AL, 10; AL AL + 10
ADD [BX], AL; [DS:BX] [DS:BX] + AL
Numerical computation
SUB :
SUB <dst>, <src>; dst dst -src
Example: SUB AX, BX; AX AX - BX
SUB AL, 10; AL AL - 10
SUB [BX], AL; [DS:BX] [DS:BX] - AL
Numerical computation
MUL
MUL <src>;
Scr must be an variable
description:
• If src is 8 bit: AX AL *src
• If src is 16 bit: DXAX AX * src
Example: 10 * 30
MOV AL, 10; AL 10
MOV BL, 30; BL 30
MUL BL; AX AL * BL
Numerical computation
DIV
DIV <scr>
Scr must be a variable
description:
• If scr is 8 bit: AX : scr; AL= thuong so; AH= remaining
• If scr is 16 bit: DXAX :scr; AX = DX= remaining
Example: 100 : 30
MOV AX, 100; AL 100
MOV BL, 30; BL 30
DIV BL; AX : BL; AL = 3, AH = 10
Logical computation
NOT, AND, OR, and XOR
0 0 1 0 0 0
0 1 1 0 1 1
1 0 0 0 1 1
1 1 0 1 1 0
Bit computation
CF MSB LSB 0
Bit computation
SHR
SHR <dst>, 1
SHR <dst>, CL
• CF=LSB (Least Significant Bit)
• MSB (Most Significant Bit)=0
• Bits between MSB and LSB are right shifted by 1 bit
Example:
MOV AL, 80H; 1000 0000B (128)
SHR AL, 1; 0100 0000B (64)
MOV CL, 2
SHR AL, CL; 0001 0000B (16)
0 MSB LSB CF
Bit computation
ROL
ROL <dst>, 1
ROL <dst>, CL
• CF=MSB (Most Significant Bit)
• LSB (Least Significant Bit)= MSB
• Bits between MSB and LSB are left shifted by 1 bit
Example:
MOV AL, 88H; 1000 1000B
ROL AL, 1; 0001 0001B
MOV CL, 2
ROL AL, CL; 0100 0100B
CF MSB LSB
Bit computation
ROR
ROR <dst>, 1
ROR <dst>, CL
• CF=LSB (Least Significant Bit)
• MSB (Most Significant Bit)=LSB
• Bits betweeb MSB and LSB are right shifted by 1 bit
Eg.:
MOV AL, 88H; 1000 1000B
ROR AL, 1; 0100 0100B
MOV CL, 2
ROR AL, CL; 0001 0001B
MSB LSB CF
Flow control instructions
program flow control instructions can change the order of
instruction execution;
Eg.:
Unconditional jump: JMP
Conditional jump: JE, JZ, JNE, JNZ, JL, JLE, JG, JGE, ...
Loop: LOOP, LOOPE, LOOPZ
CALL
RET
Flow control instructions
JMP
JMP <label>
Eg.:
START:
ADD AX, BX
SUB BX, 1
......
JMP START ; jump to START
Flow control instructions
Conditional jump: JE, JZ, JNE, JNZ, JL, JG
JE <label> : jump if equal
JZ < label > : jump if zero
JNE < label > : jump if not equal
JNZ < label > : jump if not zero
JL < label > : jump if less than
JLE < label > : jump if less than or equal
JG < label > : jump if greater than
JGE < label > : jump if greater than or equal
Flow control instructions
Example: sum from 1 to 20
MOV AX, 0 ; AX is sum
MOV BX, 20 ; BX for counting
START:
ADD AX, BX ; adding
SUB BX, 1 ; BX=BX-1
JZ STOP ; jump to STOP if BX = 0
JMP START ; jump to START
STOP: ....
Flow control instructions
LOOP
LOOP <label>
Instruction block iterately executes if CX <>0. CX automatically
decreases by 1 after one loop executing one time.
Eg.: sum from 1 to 20
MOV AX, 0 ; AX=sum
MOV CX, 20 ; CX=number of loops
START:
ADD AX, CX ; adding
LOOP START ; if CX=0 stop
; otherwise CX CX-1 and
jump to START
Flow control instructions
INT,CALL and RET
INT <interrupt number>
• CALL <sub-prog>; call a sub-program
• RET ; return from a sub-program
Example:
CALL GIAITHUA ; call the sub-program GIAITHUA
.....
; code of sub-program
GIAITHUA PROC;
code of sub-program
RET ;
GIAITHUA ENDP ; ends
Other instructions
NOP (No Operation):
• NOP doesn’t change state of the machine; taking an instruction
cycle time
HLT (Halt)
• HLT stops a running program
Other instructions
INC
INC <dst> ; dst dst+ 1
DEC
DEC <dst> ; dst dst– 1
CMP
CMP <dst>, <src>