Chapter 04
Chapter 04
Multiple Cores,
Multiple Roles,
Hardware Priorities,
Generality,
High-speed
Modes of Execution
In most CPUs, the hardware uses a set of parameters to handle the
complexity and control operation → the hardware has multiple
modes of execution.
At any given time, the current execution mode determines how the
CPU operates
Processor
• Processor organization
Structure and • Register organization
Function
Overview
Things that the processor must do
Control and status registers: Used by the control unit to control the
operation of the processor and by privileged, operating system
programs to control the execution of programs.
Register Organization
User-visible registers: Control and status registers
General purpose Program counter (PC)
Data
Instruction register (IR)
Addressing
Segment pointers Memory address register (MAR)
Index registers
Memory buffer register (MBR)
Stack pointers
Trap flag (TF): When set, causes an interrupt after the execution of
each instruction. This is used for debugging.
Interrupt enable flag (IF): When set, the processor will recognize
external interrupts.
Maskable interrupts: INTR – processor does not recognize unless the IF is set
• Machine instruction
characteristics
Instruction Sets: • Types of operands
Characteristics • Types of operations
and Functions
Elements of a Machine Instruction
Operations: Opcode
Addresses
Numbers
Characters
Logical data
x86 Operation Types
Data movement
Instruction Description
MOV Move operand, between registers or between register
and memory
PUSH/PUSHA Push (Push all) operand/registers onto stack
MOVSX Moves a byte to a word or a word to a DWORD
with twos-complement sign extension.
LEA Loads the offset of the source operand, rather than its
value to the destination operand
XLAT Table lookup translation. Replaces a byte in AL with a
byte from a user-coded translation table
IN, OUT Input, output operand from I/O space
x86 Operation Types
Arithmetic
Instruction Description
ADD Add operands
SUB Subtract operands
MUL Unsigned integer multiplication, with byte, word, or
double word operands, and word, Dword, or Qword
result
DIV Unsigned divide
IDIV Signed divide
x86 Operation Types
Logical/Control transfer
Instruction Description
NOT, AND, OR, XOR NOT, AND, OR, XOR operands
SHR/SHL Shift logical right or left
SAR/SAL Shift arithmetic right or left
ROR/ROL Rotate right or left
DIV Unsigned divide
IDIV Signed divide
JMP Unconditional jump
CALL Call subroutine: Transfer control to another
location
JE/JZ Jump if equal/zero
LOOPE/LOOPZ Loops if equal/zero
x86 Operation Types
String operations
Instruction Description
LODS Load byte, word, dword of string
MOVS Move byte, word, dword string. The instruction operates
on one element of a string, indexed by registers ESI and
EDI
36
The original model was then renamed real mode, and the new
version was named protected mode.
Real mode address space
With 20 address lines of 8086/8088 processor,
address space in real mode run from 00000 to
0FFFFh (1 megabyte of memory),
Base:Offset
• Immediate Addressing
• Direct Addressing
• Indirect Addressing
x86 Addressing • Register Addressing
Modes • Register Indirect Addressing
• Displacement Addressing
• Stack Addressing
Addressing Modes
Processor Instruction:
Opcode Operand
Advantages:
Example:
Instruction
MOV AX, 1502h
operand
ADD AX, 5
Direct Addressing
The address field contains the effective address of the operand
Instruction
Example: address
Example:
Instruction
MOV BX, ARRAY address
operand
MOV [BX], 100
ADD BX, 2
ARRAY 10 DW 0
Register Addressing
Similar to direct addressing. The only difference is that the address
field refers to a register rather than a main memory address
Example:
MOV BX, AX
MOV COUNT, CX
Example:
Address
MOV BX, 1B67h 1B66 35
1B67 69
MOV AX, [BX]
1B68 1B
JMP [BX] ; Jump address in data segment 1B69 24
1B6A 01
MOV AX, [DI] ; DS:[DI]
1B6B
MOV AX, [BP] ; SS:[BP]
Displacement Addressing
A very powerful mode of addressing combines the capabilities of
direct addressing and register indirect addressing
Relative addressing
Indexing
Relative Addressing
Example:
…
Address
MOV AX, [BX+2] ; AX = 0124h: Relative
1B66 35
Or 1B67 69
MOV BX, ARRAY ; indirect 1B68 1B
… 1B69 24
1B6A 01
MOV BX, [ARRAY+2]; relative
1B6B
Indexed Addressing
Use disp[reg] or [disp+reg] to refer to memory location
Example:
MOV AL, Disp[BX] ; MOV DL, [BX+Disp]
Example:
MOV AL, [BX][SI] ; MOV AL, [BX+SI]
Example:
MOV AL, disp[BX][SI] ; MOV AL, [BX+SI+disp]
[BX] [SI]
Disp
[BP] [DI]
Stack Addressing
A stack is a linear array of locations. It is sometimes referred to as a
pushdown list or last-in-first-out queue.
Items in stack are appended to the top of the stack so that, at any
given time, the block is partially filled.