Chap2 Processor
Chap2 Processor
Chap2 Processor
1
fit@hcmus
fit@hcmus
REMIND
Inside a CPU
Abstraction layer
2
fit@hcmus
What will you learn?
3
fit@hcmus
Instruction
4
fit@hcmus
Instruction Set Architecture (ISA)
The format and behavior of a machine-level program is
defined by the instruction set architecture
Different computers have different instruction sets but
with many aspects in common
Commonly ISA:
• MIPS: used in embedded • IA-16: 16-bits processor (Intel 8086, 80186, 80286)
system • IA-32: 32-bits processor (Intel 80368 – i386, 80486
• ARM: A64, A32, T32 – i486, Pentium II, Pentium III …)
• Power-PC • IA-64: 64-bits processor (Intel x86-64 - Pentium D…)
5
fit@hcmus
ISA design: CISC & RISC
Complete Instruction Set Computer (CISC): includes
many instructions, from simple to complex
Reduced Instruction Set Computer (RISC): consists of
only simple instructions
Which one is better?
6
fit@hcmus
Discussion
7
fit@hcmus
Assembly Language
A symbolic representation of machine code, clearer than
in machine code
Each assembly instruction represents exactly one
machine instruction
Ex: Save the value 5 decimal in the register $4
Machine language: 00110100 0000100 00000000 00000101
Assembly: ori $4, $0, 5
opcode dest reg src reg
immediate
8
fit@hcmus
Assembly Language
Since each processor has its own register structure and
instruction set when setting the assembly, it must be
clear which processor is set, or the family of the
processor.
Ex:
Assembly for MIPS
Assembly for the line of Intel 8086 processors
9
fit@hcmus
Compiler
10
fit@hcmus
Assembler
A program that translates a symbolic version of instructions
into the machine code
A single processor (1 set of definitions) can have multiple
assemblers from different vendors running on different
operating systems.
Ex: list of assembler for x86 architecture
A86, GAS, TASM, MASM, NASM
The Assembly program depends on the assembler it
uses
11
fit@hcmus
Discussions
Who will compile the compiler? (It’s also a program)
Assembler
How the hardware execute a program?
Loader & Linker
12
fit@hcmus Linker
A systems program that combines independently
assembled machine language programs (object file) and
resolves all undefined labels into an executable file.
Loader
A systems program that places an object program in
main memory so that it is ready to execute.
13
fit@hcmus
14
fit@hcmus
A translation
hierarchy for C
Chap2, A. Patterson and J. L. Hennessy, Computer Organization and Design: The Hardware/Software Interface,5th 15
ed, 2014 Figure 2.21
fit@hcmus
Chap2, A. Patterson and J. L. Hennessy, Computer Organization and Design: The Hardware/Software Interface,5th ed, 16
2014 Figure 2.23
fit@hcmus
Realistic
Model
17
fit@hcmus
Instruction processing
18
fit@hcmus
Fetch cycle
• PC (Program Counter)
Store the next instruction’s address
• MAR (Memory Address Register)
Store the address of a location in memory
(output to address bus)
• MBR (Memory Buffer Register)
A word of data to be written to
memory or the word most recently read
(output to data bus)
• IR (Instruction Register)
Contain the most recently fetched
instruction
19
fit@hcmus
Fetch cycle
• The control unit move the instruction
which has address in PC regs to IR
Default update PC reg:
PC += size of the fetched instruction
• The fetched instruction is loaded into an
IR, where the opcode and operand are
analyzed
• Data are exchanged with memory using
the MAR and MBR
20
fit@hcmus
ALU
00001100 01000010 00000001
00010000 00000001 01000000
00010000 x R1
…
00010011 R1+y R1
x 00010110 R1 x
y ….
… 01000000 ….
01000010 ….
21
fit@hcmus
Execute cycle
Elapsed time
• Total response time, including all aspects: processing,
i/o, idle time, OS overhead
CPU time
• Time spent processing a given task
• Comprise user CPU time and system CPU time
• Different program are affected differently by CPU and
system performance
23
Clock Cycles
fit@hcmus
24
fit@hcmus
CPU Time
𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠 𝐶𝑃𝑈 𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒𝑠 𝑠𝑒𝑐𝑜𝑛𝑑𝑠
CPU time = × ×
𝑃𝑟𝑜𝑔𝑟𝑎𝑚 𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛 𝐶𝑃𝑈 𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒𝑠
26
27