Professional Documents
Culture Documents
Memory
CPU coordinates transfer between I/O and memory. Direct Memory Access (DMA).
CPU
Memory
I/O
Address Bus
Control Bus Data Bus Memory
Instruction Decoder
ALU Data Paths for Dyadic Operations Using a Single Accumulator Register.
Operand #1: Current contents of accumulator
A Result: Replaces old contents of accumulator ALU Operand #2: Read from memory Accumulator B Memory Data Bus
Branch Address
+1
Program Counter
286
1982
2.7
12.5 MHz
16
16
16 MB
None
386
1985
6.0
20 MHz
32
32
4 GB
None
486
1989
20
25 MHz
32
32
4 GB
8 KB L1
Pentium
1993
100
60 MHz
32
64
4 GB
Pentium Pro
1995
440
200 MHz
32
64
64 GB
Pentium II
1997
466
266
32
64
64 GB
Pentium III
1999
1000
500
32
64
64 GB
Instruction Formats
Operand Fields
0 1 2
Example
Description
CLC Clear the carry flag to 0. INC AX Increment contents of register AX MOV AX,BX Copy contents of BX into AX.
Destination operand
Source operand
Segment Registers
Hidden Part 79 16 15 Visible Part 0
CS DS
SS
ES FS
Copies of GDT entries corresponding to value of segment selectors (not used in Real Mode)
Segment Selector
GS
Copyright 2000, Daniel W. Lewis. All Rights Reserved.
Flags Register
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF
DF
IF
TF
SF
ZF
AF
PF
CF
Flag Overflow Direction Interrupt Enable Trap Sign Zero Auxiliary Carry Parity Carry
Bit 11 10 9 8 7 6 4 2 0
Description Previous result caused arithmetic overflow. 1 = auto-decrement, 0 = auto-increment. Interrupts are enabled Single step mode enabled Previous result was negative Previous result was zero Previous result produced a BCD carry Previous result had even parity Previous result produced a carry put of MSB
In little endian format, the address of a 32-bit quantity is the same as the address of its least significant byte.
Copyright 2000, Daniel W. Lewis. All Rights Reserved.
The Stack
Instruction sequence:
PUSH EBX PUSH AX PUSH CS
Address
SS:[ESP+10] SS:[ESP+8] SS:[ESP+4]
Memory contents
value from EBX(32 bits) value from AX (16 bits) value from CS (32 bits)
PUSH EDX
SS:[ESP]
Top of stack
Real-Mode Addressing
16-bit segment 0000 12 MSBs of offset padded with four 0's on the left 16-bit offset 4 LSBs of offset
16-bit Adder
4 LSBs of result
Real-Mode Addressing
The segment value establishes a reference point to the beginning of a 64kb block of memory; the offset is a positive displacement from this reference. Offset = 012316 Segment = 8B2E16
8B2E016
Instruction Operands
Constant Immediate Mode
Embedded within representation of instruction.
Protected Mode:
Address = R1 + C1 R2 + C2
Immediate Mode
(Example: MOV AX,12345)
opcode
16-bit operand
Instruction Operands
Constant Immediate Mode
Embedded within representation of instruction.
Protected Mode:
Address = R1 + C1 R2 + C2
Register Mode
(Example: MOV AX,CX)
opcode
code AH CH AX SI DS
registers AL BH CL DH BX CX DI SP CS SS
BL DL DX BP ES
Instruction Operands
Constant Immediate Mode
Embedded within representation of instruction.
Protected Mode:
Address = R1 + C1 R2 + C2
Real-Mode Addressing
Base Index Constant
BX BP None +
SI DI None +
opcode
16-bit offset
memory operand
Address = RB + RI + constant
opcode
memory operand
or
operand
Based: BX or BP Indexed: SI or DI
Address = RB + RI + constant
or
Address = RB + RI + constant
Copyright 2000, Daniel W. Lewis. All Rights Reserved.
opcode
code
code
displacement
memory
BX or BP SI or DI
operand
Address = RB + RI + constant
Copyright 2000, Daniel W. Lewis. All Rights Reserved.
32 bits
Instruction Operands
Constant Immediate Mode
Embedded within representation of instruction.
Protected Mode:
Address = R1 + C1 R2 + C2
Protected-Mode Addressing
Base EAX EBX ECX EDX ESI EDI EBP ESP None Index EAX EBX ECX EDX ESI EDI EBP None Scale Factor Displacement
1
2
None +
8-bit
3
4
16-bit
32-bit
Operand Sizes
May be implicit: May be inferred: INC EAX MOV AL,[EBX]
Size of register EAX is 32 bits.
AL is 8 bits, so register EBX contains the address of an 8-bit memory operand.
May be explicit:
PUSH AX
0101 0000
Prefix Byte (66h)
PUSH EAX
PUSH EAX
PUSH AX
MOV AX,imm16
1011 1000
Prefix Byte (66h)
MOV EAX,imm32
(2 bytes follow)
MOV EAX,imm32 (4 bytes follow)
(4 bytes follow)
MOV AX,imm16 (2 bytes follow)
MOV AX,[mem16] (2-byte adrs field) MOV AX,[mem32] (4-byte adrs field)
1010 0001
Prefix Byte (67h)
MOV EAX,[mem32] (4-byte adrs field) MOV EAX,[mem16] (2-byte adrs field)
Stack Instructions
PUSH src16 PUSH src32 PUSHF PUSHA ; ESP ESP-2, MEM[SS:ESP] src16 ; ESP ESP-4, MEM[SS:ESP] src32 ; ESP ESP-4, MEM[SS:ESP] EFlags ; Pushes EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
; dst16 MEM[SS:ESP], ESP ESP+2 ; dst32 MEM[SS:ESP], ESP ESP+4 ; EFlags MEM[SS:ESP], ESP ESP+4 ; Pops EDI, ESI, EBP, skip, EBX, EDX, ECX, EAX
Arithmetic Instructions
ADD dst,src ADC dst,src SUB dst,src SBB dst,src INC dst DEC dst NEG dst MUL src ; unsigned IMUL src ; signed DIV src ; unsigned IDIV src ; signed CBW CWD/CDQ CMP dst,src
32 31
MOV
ADC MOV
EAX,[x+4]
EAX,[y+4] [z+4],EAX
63 [y+4] [y]
32 31
[z+4]
[z]
Operation AL src8
AX src16 EAX src32
Product AX
DX.AX EDX.EAX
Operation
AX src8 DX.AX src16
Quotient Remainder
AL AX EAX AH DX EDX
Source
AL AX EAX
Destination
AX DX.AX EDX.EAX
signed int a, b, c ;
a=b/c; MOV EAX,[b] SUB EDX,EDX DIV DWORD [c] MOV [a],EAX
RCR:
ROR: SAR:
SHL:
SHR:
Step #1:
[x+4]
CF
SHR [X+4],1
31
Step #2:
CF
[x]
RCR [X],1