MP 3 4
MP 3 4
Outline
• Intel microprocessors history
• Basic microprocessor and system architecture
• Memory
• Programming model
• Memory addressing
• Real mode
• Protected mode
• Differences between C and ASM
3
Microprocessor Architecture
Basic Components
• CPU Registers
• special memory locations constructed from flip-flops and
implemented on-chip
• e.g., accumulator, count register, flag register
• Arithmetic and Logic Unit (ALU)
• ALU is where most of the action takes place inside the CPU
• Bus Interface Unit (BIU)
• responsible for controlling the address and data busses when
accessing main memory and data in the cache
• Control Unit and Instruction Set
• CPU has a fixed set of instructions with which to work, e.g., MOV,
CMP, JMP, ADD
5
Microprocessor Architecture
Instruction processing
• Processing of an instruction by a microprocessor consists
of three basic steps
• (1) fetch instruction from the memory,
• (2) decode the instruction, and
• (3) execute (usually involves accessing the memory for getting
operands and storing results)
• Operation of an early processor, e.g., 8085
Microprocessor Architecture
Instruction processing
• Modern microprocessors can process several instructions
simultaneously at various stages of execution
• this ability is called pipelining
• Operation of the pipelined microprocessor, e.g., 80486
Generate Generate
Address Address Address Unit
1 2
7
System Architecture
A19
Address Bus provides a memory Address Bus
address to the system memory and
I/O address to the system I/O A0
devices
8086 D15 To memory
Data Bus transfers data between Data Bus
System (16 bit) and I/O
the microprocessor and the memory
and I/O attached to the system D0
Memory
• Microprocessor addresses a maximum of 2n different
memory locations, where n is a number of bits on the
address bus.
• The memory system is divided into three main parts: TPA
(transient program area), system area, and XMS (extended
memory system).
• The first 1M byte of memory (TPA and system area) is called
the real or conventional (DOS) memory system because
each Intel microprocessor is designed to function in this area
by using its real mode of operation.
• Computer systems based on the 80286 through the Core2
not only contain the TPA (640K bytes) and system area
(384K bytes), they also contain extended memory.
10
Memory
11
Memory (cont.)
• Logical Memory
• 80x86 supports byte addressable memory
• byte (8 bits) is a basic memory unit
• e.g., when you specify address 24 in memory, you get the entire
eight bits, nothing less, nothing more
• when the microprocessors address a 16-bit word of memory, two
consecutive bytes are accessed
• Physical Memory
• The physical memories of 80x86 family differ in width
• e.g., 8088 memory is 8 bits wide,
• 8086, 80286 memory is 16 bits wide, and
• 80386dx, 80486 memory is 32 bits wide
• Pentiums memory is 64 bits wide
13
Memory (cont.)
• For programming there is no difference in memory width,
because the logical memory is always 8-bit wide
• Memory is organized in memory banks
• a memory bank is an 8-bit wide section of the memory.
• e.g., the 16-bit microprocessors contain two memory banks to form
a 16-bit wide section of memory that is addressed as bytes or
words.
• 32-bit microprocessors contain four memory banks to form a 32-bit
wide section of memory that is addressed as bytes, words or
double words.
14
FFFFFD FFFFFC
FFFFFB FFFFFA
8 bits
8 bits
000005 000004
000003 000002
000001 000000
D15 - D8 D7- D0
15
Memory
Data Types
• Numbers
• bit (e.g.: 0,1) ; nibble = 4 bits
• DB: define Byte = octet = 8 bits
• DW: define Word = 2 bytes = 16 bits (80x86 terminology)
• DD: define Doubleword = 4 bytes = 32 bits (80x86 terminology)
• DQ: define Quadword = 4 bytes = 64 bits (80x86 terminology)
• Intel uses little endian format (i.e., least significant byte at lower address)
• Signed Integers (2's complement)
• Text
• Letters and characters (7-bit ASCII standard), e.g., 'A'=65=0x41
• Extended ASCII (8-bit) allows for extra 128 graphics/symbols)
• Collection of characters = Strings
• Collection of Strings = Documents
17
Memory
Data Types (cont.)
• Programs
• Commands (MOV, JMP, AND, OR, NOT)
• Collections of commands = subroutines
• Collection of subroutines = programs
• Floating point numbers (covered later)
• Images (GIF, TIF, JPG, BMP)
• Video (MPEG, QuickTime, AVI)
• Audio (voice, music)
18
Examples
20
21
22
Real Numbers
Float converter:
https://www.h-schmidt.net/FloatConverter/IEEE754.html
23
24
Programming Model
Registers (Program visible)
Note:
32 bit registers are
not available on
8086, 8088, 80286
25
Programming Model
64-bit Extension
26
Programming Model
Multipurpose Registers
• RAX (accumulator) is addressable as RAX, EAX, AX, AH, or AL.
• It often holds the temporary result after an arithmetic and logic operation.
• EAX, RAX may hold offset addresses.
• RBX (base) is addressable as RBX, EBX, BX, BH, or BL.
• It often holds the base (offset) address of data located in the memory.
• EBX, RBX can address memory data.
• RCX (count) is addressable as RCX, ECX, CX, CH, or CL.
• It often holds the count for various instructions (shift, rotate, REP/
REPE/REPNE and LOOP).
• ECX, RCX can address memory data.
• RDX (data) is addressable as RDX, EDX, DX, DH, or DL.
• It often holds a part of the result from a multiplication or part of the dividend
before a division.
• EDX, RDX can address memory data.
27
Programming Model
Multipurpose Registers
• RBP (base pointer) is addressable as RBP, EBP, or BP.
• It points to a memory location for memory data transfers.
• RDI (destination index) is addressable as RDI, EDI, or DI.
• it often addresses string destination data for the string instructions.
• RSI (source index) is addressable as RSI, ESI, or SI.
• It often addresses string source data for the string instructions.
• R8 through R15 are found are only found in the Pentium 4 and
Core2 if 64-bit extensions are enabled.
• Data in these registers are addressed as 64-, 32-, 16-, or 8-bit
sizes and are of general purpose.
• Most applications will not use these registers until 64-bit processors
are common.
28
Programming Model
Special-Purpose Registers
• RIP (instruction pointer) addresses the next instruction in a
section of memory defined as a code segment.
• This register is IP (16 bits) when the microprocessor operates in the real
mode and EIP (32 bits) when the 80386 and above operate in the
protected mode. In the 64-bit mode, RIP contains a 40-bit address at
present to address a 1T flat address space.
• The instruction pointer can be modified with a jump or a call instruction.
• RSP (stack pointer) addresses an area of memory called the
stack (LIFO).
• The stack memory stores data through this pointer using PUSH and POP
instructions that address stack data.
• This register is referred to as SP if used as a 16-bit register and ESP if
referred to as a 32-bit register.
• RFLAGS indicate the condition of the microprocessor and
control its operation.
29
Programming Model
Flag Register
Programming Model
Segment Registers
• Segment registers are 16-bit special-purpose registers
that generate memory addresses along with other
registers in the microprocessor
• CS(code) defines the starting address of the section of
memory-holding code (programs and procedures used by
programs)
• DS(data) a section of memory that contains most data used
by a program
• ES(extra) an additional data segment
• SS(stack) defines the area of memory used for the stack
• FS and GS (available on 80386, 80486 and later) allow two
additional memory segments for access by programs
31
Descriptors
39
Example
41
Program-Invisible Registers
• The program-invisible registers are not directly addressed
by software.
• These registers control the microprocessor when operated
in protected mode (80286 and above).
• Each of the segment registers contains a program-invisible
portion (cache) used in the protected mode.
• The GDTR (global descriptor table register) and IDTR
(interrupt descriptor table register) contain the base address
of the descriptor table and its limit.
• The LDTR (local descriptor table register) is loaded with a
selector, just as a segment register is loaded with a selector.
42
Program-Invisible Registers
43
Memory Paging
• The memory paging mechanism located within the 80386
and above allows any physical memory location to be
assigned to any linear address.
• The linear address (logical) is defined as the address
generated by a program.
• The physical address is the actual memory location
accessed by a program.
• With the memory paging unit, the linear address is invisibly
translated to any physical address, which allows an
application written to function at a specific address to be
relocated through the paging mechanism.
• It also allows memory to be placed into areas where no
memory exists.
46
Paging Registers
47
48
49
Peripherals
• Memory-mapped devices (special memory locations in
the normal address space of the CPU)
• BIOS: 0xF0000-0xFFFFF (bootstrap, I/O calls)
• Video: 0xA0000-0xBFFFF and vBIOS: 0xC0000-0xC7FFF
• I/O mapped devices (sound card, com ports, parallel
port)
• I/O addresses different than Memory addresses
• Address Range: 0x0000 - 0xFFFF (16-bit)
• Interrupts
• Notifies the CPU when an event has occurred
• Timer [update clock] , serial I/O [input data], Parallel I/O [ready]
• Network adapter [packet arrived]
50
C vs. ASM
x86 assembly C
Null EQU 0 #define null 0
start: Start()
{
mov ax, cs
mov ds, ax
myseg ENDS
51
C ASM Description
int x = 0x5 x db 05h Allocate memory for a variable and initialize it with
a value.