Interface Hardware-Software
Aula 2-1
Arquitetura Processadores Intel x86
Prof. Dr. Stefan Michael Blawid
IHS - §2 MPUs x86 2
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 3
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 4
ISA Intel x86 History
Evolution ensuring backward compatibility: 8080 (1974): 8-bit microprocessor
8086 (1978): 8080 extension to 16 bits Dedicated 16-bit registers
8087 (1980): Floating point coprocessor Add floating point statements and stack
80286 (1982): 24-bit addresses and Memory Management Unit (MMU) Memory protection model
80386 (1985): 32-bit extension (called IA-32) Addressing Modes and Additional Operations 32-bit registers and addressing
I486 (1989): Pipeline utilization, on-chip caches Compatible Competitors: AMD, Cyrix, …
IHS - §2 MPUs x86 5
ISA Intel x86 History (cont.)
Always evolving …
Pentium (1993): Superscalar
Later versions included Multi-Media eXtension (MMX) instructions
The Famous FDIV Instruction Bug Pentium III (1999)
Added Streaming SIMD Extensions (SSE) instructions and associated registers
70 instructions added, 4 single precision floating point operations could be done in parallel
Pentium 4 (2001)
Added 144 instructions (SSE2)
It allowed double precision floating point operations to be performed in parallel
IHS - §2 MPUs x86 6
ISA Intel x86 History (cont.)
And even more so …
AMD64 (2003): Extended the architecture to 64 bits Increased registers to 64 bits
Increased number of registers
EM64T – Extended Memory 64 Technology (2004) AMD64 adopted by Intel (with refinements)
Added 13 SSE3 instructions Intel Core (2006)
Added 54 SSE4 instructions AMD64 (2007)
Added 170 SSE5 instructions
IHS - §2 MPUs x86 7
Processor Execution Cycle
1) Fetch an instruction from the memory
2) Decode the instruction (i.e., identify the instruction)
3) Execute the instruction (i.e., perform the action specified by the instruction)
IHS - §2 MPUs x86 8
Storing Multibyte Data
IHS - §2 MPUs x86 9
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 10
Intel 32-bit Architecture (IA-32)
Ten 32-bit and six 16-bit registers
Grouped into general, control, and segment registers
IHS - §2 MPUs x86 11
Data registers
There are four 32-bit data registers that can be used for arithmetic, logical, and other operations. They can be used as follows:
Four 32-bit registers (EAX, EBX, ECX, EDX); or Four 16-bit registers (AX, BX, CX, DX); or
Eight 8-bit registers (AH, AL, BH, BL, CH, CL, DH, DL) Some specific uses, e.g.,
EAX (or AX, or AL) must contain one operand for multiplication ECX (or CX) must contain the loop count for iterative instructions
IHS - §2 MPUs x86 12
Example
MUL CL
IHS - §2 MPUs x86 13
Index and Pointer Registers
Index Registers should be used in statements that manipulate strings: These types of statements usually implicitly increment / decrement these registers.
The pointer registers are mainly used to maintain the stack ESP holds the address of the top of the stack and is
incremented / decremented by POP / PUSH instructions
EBP is the base pointer for memory access
IHS - §2 MPUs x86 14
Segment Registers
Support the segmented memory organization and point to where these segments are located in the memory
CS points to the instruction part DS points to the data part
SS points to the stack segment
IHS - §2 MPUs x86 15
Control Register: Instruction pointer
IP points to the next instruction to be executed within the current code segment
Cannot be explicitly changed by programmer Implicitly modified by certain instructions
32-bit (EIP) or 16-bit (IP) addresses
The FLAGS register (next slide) stores the CPU state (status flags) and also controls it (control and system flags)
Implicitly modified by the instructions
IHS - §2 MPUs x86 16
Control register: FLAGS
IHS - §2 MPUs x86 17
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 18
Where Are the Operands?
Instructions use the format: [label] mnemonic [operands] [;comment] Most assembly language instructions require operands
An operand required by an instruction may be in any one of the following locations:
in a register internal to the processor; in the instruction itself;
in main memory (usually in the data segment); at an I/O port
IHS - §2 MPUs x86 19
Addressing Modes
In arithmetic / logical instructions first operand is origin and destiny
Register-addressing mode is the most efficient way of specifying operands because they are within the processor and, therefore, no memory access is required
Immediate Addressing mode: Operand is in the code segment Memory Addressing: Operand is in the data segment
First source/destiny operator Second source operator
Register Register
Register Immediate
Register Memory
Memory Register
IHS - §2 MPUs x86 20
Register-Addressing Mode
IHS - §2 MPUs x86 21
Immediate Addressing Mode
The immediate source operand can be an 8,16 or 32-bit number Cannot be used for segment registers!
IHS - §2 MPUs x86 22
Memory Addressing Modes
To locate a data item in the data segment, we need two components: the segment start address and an offset value within the segment. The offset value is often called the effective address. Various memory-addressing modes differ in the way the offset value of the data is specified. For 16-bit addresses:
IHS - §2 MPUs x86 23
Direct Addressing Mode
The offset value is specified directly as part of the instruction Must be specified using square brackets ([])
Default segment is DS, otherwise must be specified, e.g.:
IHS - §2 MPUs x86 24
Indirect Addressing Mode
The effective address of the data is in one of the general registers Must be specified using square brackets ([])
Only BX, BP, SI, DI can be used.
IHS - §2 MPUs x86 25
Based Addressing
The effective address is computed: A register acts as the base register and a displacement value is added
Must be specified using square brackets ([]) Only BX, BP can be used as base register Value must be a signed 8- or 16-bit number Default segment is DS for BX and SS for BP
IHS - §2 MPUs x86 26
Indexed Addressing
Similar to base addressing, however only SI and DI (index) registers can be used as base registers
Must be specified using square brackets ([]) Default segment is DS
IHS - §2 MPUs x86 27
Based-Indexed Addressing
Memory operand address is the result of the sum of segment, base register, index register, and offset value
Specification of a displacement value not required Must be specified using square brackets ([])
IHS - §2 MPUs x86 28
Memory addressing for 32-bit addresses
A scale factor may be applied for indexed and based-indexed addressing (support for two-dimensional arrays)
IHS - §2 MPUs x86 29
I/O port addressing
Specific to I/O, the operand is given by the (immediate) address of a port or is given by the address contained by the DX register
IHS - §2 MPUs x86 30
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 31
IA-32 instruction format
IHS - §2 MPUs x86 32
Instruction prefixes
Prefix Bytes Modify Operation: Lock and repeat; Segment override; Branch hints; Operand-size override; Address-size override
IHS - §2 MPUs x86 33
Opcode
The primary opcode of the instruction. Some instructions already
codify additional informations in their own opcode. Example: direction of the operation (increment/decrement)
IHS - §2 MPUs x86 34
Postfix bytes
IHS - §2 MPUs x86 35
If the instruction specifies an immediate operand, the operand always follows any displacement bytes. An immediate operand can be 1, 2 or 4 bytes.
IHS - §2 MPUs x86 36
Some Conclusions about x86
Complex instructions make implementation difficult
HW translates instructions to simpler micro operations: Simple instructions are translated one-to-one; Complex instructions, however, one-to-many
Microengine similar to RISC
Market makes processor economically viable Performance comparable to RISC
Compilers avoid complex instructions Compatibility ties processor design
IHS - §2 MPUs x86 37
Tópicos
1) A família de microprocessadores 80x86 2) IA-32: Registradores 3) Modos de endereçamento 4) Formato de InstruçãoIHS - §2 MPUs x86 38
X86 Processor Modes of Operation
Commitment to legacy code compatibility has led Intel to adopt modes of operation on its processors
Depending on the version of the processor for which the code was written, it will run in a particular mode of operation on a newer processor.
The mode of operation determines which architecture instructions and features are accessible
Example: The IA-32 architecture
Real mode: Uses 16-bit addresses, provided to run programs written for the 8086 processor.
Protected mode: Uses 32-bit addresses, native mode of the IA-32 architecture
IHS - §2 MPUs x86 39
Protected Mode Memory Architecture
Index: Selects one of 8192 descriptors
TI: Selects one of two descriptor tables
RPL: Identifies the privilege level for protected access 32-bit offset:
Segments can span the entire memory address space (4GB) of a Pentium
IHS - §2 MPUs x86 40
Real Mode Memory Architecture
The memory address space is 1MB ➡ 20-bit physical memory address
Four least significant zero bits are not stored
16-bit offset: Segments span 64kB
IHS - §2 MPUs x86 41
Real-mode segments overlap
For each logical memory address, there is a unique physical memory address
One logical address can refer to the same physical memory address