Professional Documents
Culture Documents
Outline
• Programming Languages
• Instructions Execution
• Instructions Pipelining
2
Department of Computer Engineering and Automation
3
Department of Computer Engineering and Automation
Computer`s Components
Monitor
System unit
Keyboard
Mouse
4
Department of Computer Engineering and Automation
5
Department of Computer Engineering and Automation
I/O Units
• Each I/O port contains registers, some for data and some for
control
• I/O ports are interfaces between the CPU and the memory as well
as I/O devices
– I/O port between the CPU and the memory has an address
– I/O port between the CPU and any I/O device has no address
6
Department of Computer Engineering and Automation
I/O Units
7
Department of Computer Engineering and Automation
I/O Units
I/O Units
A button that
detects clicks
9
Department of Computer Engineering and Automation
10
Department of Computer Engineering and Automation
Registers
ALU
11
Department of Computer Engineering and Automation
12
Department of Computer Engineering and Automation
13
Department of Computer Engineering and Automation
14
Department of Computer Engineering and Automation
Registers
15
Department of Computer Engineering and Automation
Registers
• User-visible registers
– Mostly used by the computation unit to execute instructions
– Classified into
• General purpose registers
• Data registers
• Address registers
• Condition codes registers
16
Department of Computer Engineering and Automation
• Accumulator (Ax)
– The most important register
• All operations are done by means of AX
• Segment pointers
– Contain the adress of a segment (the address of the byte where the
segment starts)
– Some are used for codes, some for data
– Examples
• Code segment (CS)
– Contains the start address of the program
• Data segment (DS)
– Contains the start address of the block where data are stored
17
Department of Computer Engineering and Automation
Push C C Pop C
B A B
B
18
Department of Computer Engineering and Automation
• Flags
– Determine the status of the result of the last operation
– Examples
• Carry flag (C)
– 1: there is a carry, 0: there is no carry
• Overflow flag (O)
– 1: the result is beyond the range the register can store, 0: the result is inside
that range
• Sign flag (S)
– 1: the result is negative, 0: the result is positive
• Zero flag (Z)
– 1: the result is zero, 0: the result is not zero
19
Department of Computer Engineering and Automation
Programming Languages
20
Department of Computer Engineering and Automation
Programming Languages
21
Department of Computer Engineering and Automation
Machine Language
• E.g.
– 10100001 00000000 00000000 (fetch the content of the address “0”
and put them in the register AX)
22
Department of Computer Engineering and Automation
Assemply Language
Assemply Language
Assempler
High-Level Languages
• E.g.
– C++, Delphi, Java, C#, PHP, TCL, etc.
25
Department of Computer Engineering and Automation
High-Level Languages
26
Department of Computer Engineering and Automation
High-Level Languages
27
Department of Computer Engineering and Automation
High-Level Languages
28
Department of Computer Engineering and Automation
High-Level Languages
The program
written in assembly The registers
of the CPU
The flags
The program
Memory written in machine
content language
29
Department of Computer Engineering and Automation
Instructions Execution
30
Department of Computer Engineering and Automation
• E.g.
– Mov (OpCode) AX [1000H] (operands)
31
Department of Computer Engineering and Automation
• Fetch cycle
– Fetch the instruction from the memory
• Put the read command on the control bus
• Put the address of the instruction on address bus
• Receive the instruction on data bus and push them into the instruction
queue
32
Department of Computer Engineering and Automation
• Execution cycle
– Perform the operation
• ALU execute the operation
• The operation is executed by means of the register AX
33
Department of Computer Engineering and Automation
Start
Fetch next
Fetch cycle
instruction
Execute
Execution cycle
Interrupt disabled Instruction
Interrupt enabled
Halt
Check for interrupt
Interrupt cycle
Process interrupt
34
Department of Computer Engineering and Automation
Indirect Cycle
Indirection
Instruction Operand
fetch fetch
instruction
operands
Request
Multiple
Request
operand
Next instruction
35
Department of Computer Engineering and Automation
Data Flow
Address bus
Control bus
Data bus
PC MAR
Memory
Control
unit
36
Department of Computer Engineering and Automation
Data Flow
Address bus
Control bus
Data bus
MAR
Memory
Control
unit
37
Department of Computer Engineering and Automation
Data Flow
Address bus
Control bus
Data bus
PC MAR
Memory
Control
unit
38
Department of Computer Engineering and Automation
Instructions Pipelining
39
Department of Computer Engineering and Automation
Wait Wait
New address
Instruction Result
Fetch Instruction Execute
Discard
• Solutions: try to reduce (eliminate in the ideal case) waiting times
Pipelining
40
Department of Computer Engineering and Automation
• Let us assume that all steps require the same time to operate
41
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI DI CO FO EI WO
Instruction 4
FI DI CO FO EI WO
Instruction 5
Instruction 6 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 7
Instruction 8 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 9
Time
42
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI DI CO FO EI WO
Instruction 7
Instruction 8 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 9
Time
43
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI FO
Instruction 4 (14 time steps) theDItimeCOrequired to
EI WO
operate 9 instructions
• The time required to execute 9 instructions without
FI DI CO FO EI WO
Instruction 5 pipelining is 54 time steps
• The pipelining has reduced them to 14
Instruction 6 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 7
Instruction 8 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 9
Time
44
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI FO
Instruction 4 (14 time steps) theDItimeCOrequired to
EI WO
operate 9 instructions
• The time required to execute 9 instructions without
FI DI CO FO EI WO
Instruction 5 pipelining is 54 time steps
• The pipelining has reduced them to 14
Instruction 6 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 7
Instruction 8 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 9
Time
45
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
Instruction 4
Let us assume that
instruction 3 is a
Instruction 5 condition that lets the
program jummbing to
Instruction 6 instruction 15 (if or case
statement for example)
Instruction 7
Instruction 15
Instruction 16
Time
46
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI DI CO FO
Instruction 4
FI DI CO
Instruction 5
Instruction 6 FI DI
FI
Instruction 7
FI DI CO FO EI WO
Instruction 15
FI DI CO FO EI WO
Instruction 16
Time
47
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI FO
Instruction 4 (14 time steps) theDItimeCOrequired to operate 5 instructions
• The time required to execute 5 instructions without
FI DI CO
Instruction 5 pipelining is 30 time steps
• The pipelining has reduced them to 14
Instruction 6 FI DI
FI
Instruction 7
FI DI CO FO EI WO
Instruction 15
FI DI CO FO EI WO
Instruction 16
Time
48
Department of Computer Engineering and Automation
1 2 3 4 5 6 7 8 9 10 11 12 13 14
FI DI CO FO EI WO
Instruction 1
Instruction 2 FI DI CO FO EI WO
FI DI CO FO EI WO
Instruction 3
FI FO
Instruction 4 (14 time steps) theDItimeCOrequired to operate 5 instructions
• The time required to execute 5 instructions without
FI DI CO
Instruction 5 pipelining is 30 time steps
• The pipelining has reduced them to 14
Instruction 6 FI DI
FI
Instruction 7
FI DI CO FO EI WO
Instruction 15
FI DI CO FO EI WO
Instruction 16
Time
49
Department of Computer Engineering and Automation
Fetch Fetch
instruction operand
Decode Execute
instruction instruction
Calculate Write
operand operand
No Branch or No
Unconditional
interrupt
branch
Yes Yes
Update
PC
Empty the
pipe
50
Department of Computer Engineering and Automation
51
Department of Computer Engineering and Automation
52
Department of Computer Engineering and Automation
• Access to the memory only includes write and read in/from the memory
53