Professional Documents
Culture Documents
Week 4 Machine Instruction-RIW
Week 4 Machine Instruction-RIW
www.telkomuniversity.ac.id
How It Works? Case Study: B A
3
3 Data Register
3A A
B
1 CU
C
Instruction 2
Pointer Instruction Register
MOV B A
ALU Instruction
Decoder
Mem 2
Mem 1 1E
Mem 0 www.telkomuniversity.ac.id
DEBUG.EXE
www.telkomuniversity.ac.id
Machine Instruction Type
Basic:
• Data Transfer, ex: MOV, PUSH, POP
• Arithmetic and Logic, ex: ADD, SUB, AND, OR, SHL
• Control, ex: JMP, JZ
Additional:
• System Call
• Floating Point Processing
• String Processing
• Cryptography Processing
• Multimedia Processing (Compression/Decompression, Coding/Decoding)
• 3D Image Manipulation
www.telkomuniversity.ac.id
How Microprocessor RUNS an instruction?
www.telkomuniversity.ac.id
Microprocessor Family
www.telkomuniversity.ac.id
Machine Instruction Structure
CISC opcode ? ? ?
0 7
RISC opcode
0 5
www.telkomuniversity.ac.id
How does x86 decode instruction?
• 32 bit instruction = 6 bit opcode + operand (5 bit register select and data)
• Three types of instruction: R-type, I-type and J-type
– R-type is register instructions, with 3 register references contained in the 32-
bit instruction
– I-type specify two registers, and use 16 bits to hold an immediate value
– J-type instructions are jumps, containing a 26-bit address
Example:
• ADD R1, R2, R3 → Regs[R1] <- Regs[R2]+Regs[R3]
• LW R1,30(R2) → Regs[R1] <-32Mem[30+Regs[R2]]
• BEQZ R4, name → if (Regs[R4]==0) PC<-name; ((PC+4)-215)<=name<((PC+4)+215)
opcode
0 5
www.telkomuniversity.ac.id
How DLX does Instruction Decode?
3
3 Data Register
R1
R2
1 CU
4 R3
Program 2
Counter Instruction Register
3
ADD R3,R2, R1
ALU
Mem 2
Mem 1
Mem 0 www.telkomuniversity.ac.id
Microprocessor Speed
www.telkomuniversity.ac.id
Pipeline in x86
• Without Pipeline
t= 1 2 3 4 5 6 7 8 9 10
ADD AX,AX IF DE IF DE EX
ADD BX,CX IF DE IF DE EX
• With Pipeline
t= 1 2 3 4 5 6 7 8 9 10
ADD AX,AX IF DE IF DE EX
t= 1 2 3 4 5 6 7 8 9 10
PUSH AX IF DE EX
PUSH BX IF DE EX
ADD AX,BX IF DE EX
www.telkomuniversity.ac.id
Data Hazard #1: RAW (Read After Write)
t= 1 2 3 4 5 6 7 8 9 10
MOV AX,0000 IF DE IF DE EX
MOV AX,FFFF IF DE IF DE EX
PUSH AX IF DE EX
www.telkomuniversity.ac.id
Data Hazard #2: WAW (Write After Write)
t= 1 2 3 4 5 6 7 8 9 10
MOV AX,FFFF IF DE IF DE EX
POP AX IF DE EX
www.telkomuniversity.ac.id
Data Hazard #3: WAR (Write After Read)
t= 1 2 3 4 5 6 7 8 9 10
MOV AX,FFFF IF DE IF DE EX
MOV BX,AX IF DE IF DE EX
POP AX IF DE EX
www.telkomuniversity.ac.id
Control Hazard
Offset t= 1 2 3 4 5 6 7 8 9 10
010D POP AX IF DE EX
www.telkomuniversity.ac.id