lec03_architecture2
lec03_architecture2
Edited
By
Fehmida Sadaf Bhatti
Reading from memory
• Multiple machine cycles are required when reading from
memory, because it responds much more slowly than the
CPU. The four steps are:
– address placed on address bus
– Read Line Cycle
(RD) 1
set lowCycle 2 Cycle 3 Cycle 4
RD
Data
DATA
Reading from memory
• Multiple machine cycles are required when reading from
memory, because it responds much more slowly than the
CPU. The four steps are:
– address placed on address bus
– Read Line (RD) set low
– CPU waits one cycle for memory to respond
– Read Line (RD) goes to 1, indicating that the data is on
the data bus
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
• Cache hit: when data to be read is already
in cache memory
• Cache miss: when data to be read is not in
cache memory. When? compulsory,
capacity and conflict.
• Cache design: cache size, n-way, block
size, replacement policy
How a program runs
Multitasking
• OS can run multiple programs at the same
time.
• Multiple threads of execution within the
same program.
• Scheduler utility assigns a given amount of
CPU time to each running program.
• Rapid switching of tasks
– gives illusion that all programs are running at
once
– the processor must support task switching
– scheduling policy, round-robin, priority
IA-32 architecture
• From 386 to the latest 32-bit processor, P4
• From programmer’s point of view, IA-32
has not changed substantially except the
introduction of a set of high-performance
instructions
Modes of operation
• Protected mode
– native mode (Windows, Linux), full features,
separate memory
• Virtual-8086 mode
• hybrid of Protected
• each program has its own 8086 computer
• Real-address mode
– native MS-DOS
• System management mode
– power management, system security,
diagnostics
Addressable memory
• Protected mode
– 4 GB
– 32-bit address
• Real-address and Virtual-8086
modes
– 1 MB space
– 20-bit address
General-purpose registers
Named storage locations inside the CPU, optimized for
speed.
EAX EBP
EBX ESP
ECX ESI
EDX EDI
EFLAGS CS ES
SS FS
EIP
DS GS
Accessing parts of registers
• Use 8-bit name, 16-bit name, or 32-bit name
• Applies to EAX, EBX, ECX, and EDX
Index and base registers
• Some registers have only a 16-bit name
for their lower half. The 16-bit registers
are usually used only in real-address
mode.
Some specialized register uses (1
of 2)
• General-Purpose
– EAX – accumulator (automatically used by
division and multiplication)
– ECX – loop counter
– ESP – stack pointer (should never be used
for arithmetic or data transfer)
– ESI, EDI – index registers (used for high-
speed memory transfer instructions)
– EBP – extended frame pointer (stack)
Some specialized register uses (2
of 2)
• Segment
– CS – code segment
– DS – data segment
– SS – stack segment
– ES, FS, GS - additional segments
• EIP – instruction pointer
• EFLAGS
– status and control flags
– each flag is a single binary bit (set or clear)
Status flags
• Carry
– unsigned arithmetic out of range
• Overflow
– signed arithmetic out of range
• Sign
– result is negative
• Zero
– result is zero
• Auxiliary Carry
– carry from bit 3 to bit 4
• Parity
– sum of 1 bits is an even number
Assembler
NASM
ALINK
Debugger
AFD
mov ax,5
mov bx,10
Add ax,bx
Mov bx,15
Add ax,bx
Mov ax,0x4c00
Int 0x21
EX01.LST
Word Representation
• 4 Byte Word
• Representation in Memory
MSB LSB
Representation 1
Little Endian Notation MSB LSB
0 1 2 3
Representation 2
Big Endian Notation LSB MSB
0 1 2 3
IA-32 Memory
Management
Real-address mode
• 1 MB RAM maximum addressable (20-bit
address)
• Application programs can access any area
of memory
• Single tasking
• Supported by MS-DOS operating system
Segmented memory
Segmented memory addressing: absolute (linear)
address is a combination of a 16-bit segment value
added to a 16-bit offset
linear addresses
one segment
Segmented memory
Segmented memory addressing: absolute (linear)
address is a combination of a 16-bit segment value
added to a 16-bit offset
Overlapping
Physical Address
Calculation
16-bit segment 16-bit offset
0000 0000
20-bit segment 20-bit offset
+
1 D D D 0
+ 0 0 1 0 0
1 D E D 0
0 0 0 0 0
20 – Bit Segment = 0 Decimal
Segment Base
0 0 0 1 0
20 – Bit Physical Address = 16 Decimal
Calculating linear addresses
• Given a segment address, multiply it by 16 (add
a hexadecimal zero), and add it to the offset
• Example: convert 08F1:0100 to a linear address
multiplied by
1000h
Flat segmentation model
• All segments are mpped to the entire 32-bit physical
address space, at least two, one for data and one for code
• global descriptor table (GDT)
Paging
• Virtual memory uses disk as part of the
memory, thus allowing sum of all programs
can be larger than physical memory
• Divides each segment into 4096-byte
blocks called pages