2 Programmer View of Computer and Instruction Cycle
2 Programmer View of Computer and Instruction Cycle
(CS2523)
Chapter 3 of
Computer Organization and Architecture, William Stallings, 11 th Edition,
Pearson
• Assembler
– A program that converts an AL source code
program to machine language
– Popular Assemblers
• MASM (Microsoft Assembler)
• EMU8086 (Microprocessor Emulator)
• TASM (Borland Turbo Assembler)
• NASM (The Netwide Assembler)
Welcome to Assembly Language(AL)
• Software/Hardware Need
– Editor
• Text Editor for creating source files
– Assembler
– Linker
• Linker utility is required to produce executable file using libraries
– E-g; link32.exe
– Debugger
• For debugging/profiling of the program(errors detection/correction)
– CodeView for MASM
– Advanced Full Screen Debugger (AFD) for NASM
Welcome to Assembly Language(AL)
• Is AL portable?
Assembly Language Applications
Operating System
Level 3
Instruction Set
Architecture Level 2
Microarchitecture Level 1
Each level
Digital Logic hides the
Level 0 details of the
level below it
Programmer's View
Machine language
Native to a processor: executed directly by hardware
Instructions consist of binary code: 1s and 0s
Assembly language
Slightly higher-level language
Readability of instructions is better than machine language
One-to-one correspondence with machine language
instructions
Assemblers translate assembly to machine code
Compilers translate high-level programs to machine code
Either directly, or
Indirectly via an assembler
Compiler and Assembler
Translating Languages
High-Level Language: D = A * B + 10
mov ax, 5 ; ax = 5
mov cx, 10 ; cx = 10
mul cx ; ax = ax * cx
Translating Languages-Registers
Modern (i.e x86 and beyond) x86 processors have eight 32-bit general
purpose registers, as depicted in Figure:
Translating Languages-Registers
For the EAX, EBX, ECX, and EDX registers, subsections may be
used. For example, the least significant 2 bytes of EAX can be
treated as a 16-bit register called AX. The least significant byte
of AX can be used as a single 8-bit register called AL, while the
most significant byte of AX can be used as a single 8-bit
register called AH. These names refer to the same physical
register.
When a two-byte quantity is placed into DX, the update
affects the value of DH, DL, and EDX. These sub-registers are
mainly hold-overs from older, 16-bit versions of the
instruction set. However, they are sometimes convenient
when dealing with data that are smaller than 32-bits (e.g. 1-
byte ASCII characters).
Translating Languages-Registers
registers
I/O I/O
Central Processor Unit Memory Storage
Device Device
(CPU) Unit
#1 #2
ALU CU clock
control bus
address bus
Basic Architecture
Processor
Control unit Datapath
ALU
Control
/Status
Controller
Registers
PC IR
I/O
Memory
Datapath Operations
• Load
Processor
– Read memory location Control unit Datapath
into register ALU
• ALU operation Controller Control +1
/Status
– Input certain
registers through Registers
backstore
ALU, in register
• Store 10 11
– Write PC IR
register to memory
location
I/O
Memory
...
10
.1 .
1
.
Control Unit
• Control unit: configures the datapath
operations Processor
– Sequence of desired operations Control unit Datapath
(“instructions”) stored in memory –
ALU
“program”
Controller Control
• Instruction cycle – broken into /Status
several sub-operations, each one
clock cycle, e.g.: Registers
– Fetch: Get next instruction into IR
– Decode: Determine what the
instruction means
– Fetch operands: Move data from PC IR R0 R1
memory to datapath register
– Execute: Move data through the
ALU I/O
– Store results: Write data from 100 load R0, Memory
...
500 10
register to memory M[500]
101 inc R1, R0
501
...
102 store M[501], R1
Control Unit Sub-Operations
• Fetch Processor
ALU
instruction into IR Controller Control
– PC: program /Status
points to next
instruction IR R0 R1
– IR: holds the
PC100 load R0, M[500]
fetched I/O
instruction 100 load R0, M[500] Memory
...
500 10
101 inc R1, R0
102 store M[501], R1
501
...
Control Unit Sub-Operations
• Decode Processor
Control unit Datapath
– Determine what the
ALU
instruction means Controller Control
/Status
Registers
IR R0 R1
PC100 load R0, M[500]
I/O
Registers
10
PC100 0,IRM[500] R0 R1
load R
I/O
• Execute Processor
ALU
through the ALU Controller Control
– This particular /Status
nothing during
this sub-operation 10
PC100 0,IRM[500] R0 R1
load R
I/O
ALU
register to Controller Control
memory /Status
instruction does
nothing during 10
R0 R1
this sub-operation PC100
load R
0,IRM[500]
I/O
PC=100 Processor
Registers
10
PC 100 IR R0 R1
load R0, M[500]
I/O
PC=100 Processor
PC=101
Store Registers
FetchDecode Fetch Exec.
results
ops
clk
10
PC 101 IR R0 11
inc R1, R0
R1
I/O
PC=101
Store Registers
FetchDecode Fetch Exec.
results
ops
clk
IR 10
PC 101 inc R1, R0 R011
R1
I/O
PC=101
Store Registers
FetchDecode Fetch Exec.
results
ops
clk
IR 10
PC 101 inc bx, ax 11
ax
bx
I/O
PC=100 Processor
PC=101
Store Registers
FetchDecode Fetch Exec.
results
ops
clk
10
PC 102 IR R0 11
store M[501], R1
R1
PC=102
FetchDecode Fetch Exec. Store
I/O
results ...
ops 100 load R0, M[500] Memory
clk 500 10
101 inc R1, R0
102 store M[501], R1 .
501 1 1
..
Instruction Cycles
PC=100 Processor
PC=101
Store Registers
FetchDecode Fetch Exec.
results
ops
clk
10
PC 102 IR 11
cx
store M[501], dx
dx
PC=102
FetchDecode Fetch Exec. Store
I/O
results ...
ops 100 load cx, M[500] Memory
clk 500 10
101 inc dx, cx
102 store M[501], dx .
501 1 1
..
Architectural Considerations
ALU
buses, memory data Controller Control
interface /Status
address space
Architectural Considerations
ALU
period (f = Controller Control
1/T) /Status
than longest
register to register PC IR
delay in entire
processor
I/O
– Memory access is Memory
often the longest
Instruction Cycle
State Diagram
Advantages of High-Level Languages