MP Lect 2
MP Lect 2
Lecture 2
Lecture Content
Assembly Language Programming
Assembly Language Applications
Integer Storage Sizes
Evolution of the Microprocessor
Instruction Execution Cycle in x86 Processors
Registers in x86 Processors
Assembly Language Applications
In the early days of programming, most
application programs were written partially or
entirely in assembly language . Why?
Because programs had to fit in a small area of
memory and had to run as efficiently as possible.
17
CISC
The earliest Intel processors were based on
Complex Instruction Set (CISC) approach.
The Intel instruction set includes high-level
complex operations (powerful).
The compilers would have less work to do if
individual machine-language instructions were
powerful.
A major disadvantage to the CISC approach
is that complex instructions require a
relatively long time for the processor to
decode and execute.
An interpreter program inside the CPU written
in a language called microcode decodes and
RISC
A RISC (Reduced instruction Set) machine
language consists of a relatively small number of
short instructions that can be executed very
quickly.
Rather than using a microcode interpreter to
decode and execute machine instructions, a RISC
processor directly decodes and executes
instructions using hardware.
High-speed engineering and graphics workstations
have been built using RISC processors for many
years. These systems have been expensive
because the processors were produced in small
quantities.
Intel recognized many advantages to the RISC
CISC and RISC
CISC – complex instruction set
large instruction set
high-level operations
requires microcode interpreter
examples: Intel 80x86 family
I/O I/O
Central Processor Unit Memory Storage
Device Device
(CPU) Unit
#1 #2
ALU CU clock
control bus
address bus
Clock
synchronizes all CPU and BUS operations
Machine (clock) cycle measures time of a
single operation
Clock is used to trigger events
one cycle
0
Instruction Execution Cycle
Before executing, a program is loaded into
memory.
Executing a machine instruction requires three
basic steps: fetch, decode and execute.
Two more steps are required when the
instruction uses a memory operand: fetch
operand and store output operand.
Loop
fetch the next instruction and advance the instruction pointer
(IP)
decode the instruction
IF memory operand needed, read value from memory (fetch
operand)
execute the instruction
IF result is memory operand, write result to memory (store
output operand)
Continue loop
Instruction Execution Cycle
Fetch
The control unit fetches the instruction from the instruction queue
(cache memory) and increments the program counter (instruction
pointer IP).
Decode
The control unit decodes the instruction using Instruction Decoder.
Fetch Operand
If the instruction uses an input operand located in memory, the
control unit uses the read operation to retrieve the operand and
copy it into internal registers. Internal registers are not visible to
user programs.
Execute
The ALU executes the instruction and sends the result to memory
via internal registers.
Store output Operand
If the output operand is in memory, the control unit uses a write
operation to store the data.
Instruction Execution Cycle
PC program
I-1 I-2 I-3 I-4
Instruction Queue
(Cache Memory)
memory fetch
op1
read
op2
registers registers
instruction
I-1 register
decode
write
write
flags ALU
execute
(output)
Pipelined Execution
Pipelining makes it possible for processor to execute
instructions in parallel
Instruction execution divided into discrete stages
More efficient use of cycles, greater throughput of
instructions:
Stages
S1 S2 S3 S4 S5 S6
1 I-1
2 I-2 I-1
Cycles
3 I-2 I-1
4 I-2 I-1
5 I-2 I-1
6 I-2 I-1
7 I-2
Cycles
4 I-4 I-3 I-2 I-1
5 I-4 I-3 I-1 I-2
6 I-4 I-3 I-2 I-1
7 I-3 I-4 I-2 I-1
8 I-4 I-3 I-2
9 I-4 I-3
10 I-4
CLK
Address
ADDR
RD
Data
DATA
Cache Memory
High-speed expensive static RAM both
inside and outside the CPU.
Level-1 cache: inside the CPU
Level-2 cache: outside the CPU
EAX EBP
EBX ESP
ECX ESI
EDX EDI
EFLAGS CS ES
SS FS
EIP
DS GS
General-Purpose Registers
EAX and EBX
They are automatically used by multiplication and
division instructions . It is often called the
extended accumulator register.
ECX and EDX
They are used by the CPU automatically as a
loop counter such as (For and While Loop).
ESP
It addresses data on the stack (a system memory
structure) such as pointers.
It should never be used for ordinary arithmetic or
data transfer.
It is often called the extended stack pointer
register.
General-Purpose Registers
ESI and EDI
They are used by high-speed memory transfer
instructions.
They are sometimes called the extended source
index and extended destination index registers.
EBP
It is used by high-level languages to reference
function parameters and local variables on
the stack.
It should not be used for ordinary arithmetic or
data transfer except at an advanced level of
programming.
It is often called the extended frame pointer
register.
Accessing Parts of Registers
Use 8-bit name, 16-bit name, or 32-bit
name
Applies to EAX, EBX,
8 ECX,
8 and EDX
AH AL 8 bits + 8 bits
AX 16 bits
EAX 32 bits
Index and Base Registers
Some registers have only a 16-bit name for
their lower half:
Some Specialized Register Uses (1 of 2)
General-Purpose
EAX – Accumulator
ECX – Loop Counter
ESP – Stack Pointer
ESI, EDI – Index Registers
EBP – extended frame pointer (stack)
Segment
CS – code segment
DS – data segment
SS – stack segment
ES, FS, GS - additional segments
Some Specialized Register Uses (2 of 2)
EIP – Instruction Pointer
EFLAGS
status and control flags
each flag is a single binary bit
Segment Registers
The segment registers are used as base
locations for preassigned memory areas called
segments.