x86 Architecture & �Its Assembly language programming
Dr A Sahu
Dept of Computer Science & Engineering
IIT Guwahati
Outline
Introduction to �8086 & i386 processor
8086 Architecture
AH
AL
BH
BL
CH
CL
DH
DL
SI (Source Idx )
DI (Dest. Idx)
BP (Base Ptr )
SP (Stack Ptr)
Z (Flag Reg)
CS (Code Seg Reg)
DS (Data Seg Reg )
ES (Extra Seg Reg )
SS (Stack Seg Reg)
IP (Intr Ptr)
Operand
InDirect
Temp A
Temp B
Temp C
Q6
Q5
Q4
Q3
Q2
Q1
Sequencer
Bus Interface Unit
Execution
Unit
SUM
C BUS
A BUS
ALU
8086 Architecture
History of Intel Architectures�
History of Intel Architectures�
Superscalar Pipeline
IF
Time in base Cycle
0 1 2 3 4 5 6 7 8 9
D
IS
WB
EX
How Complex the HW will be
ILP in Superscalar processors
Fetch
Unit
Cache/
memory
Multiple instruction
Sequential stream of instructions
FU
FU
FU
Register file
Decode
& issue
Instruction/control
Data
FU
Funtional Unit
Intel P5 Architecture (Generation 5)
Instruction 1
Instruction 2
Instruction 3
Instruction 4
Decoder
EX Unit
WB Unit
Pipeline
Pipe 1
Pipe 2
Intel P6 Architecture (Generation 6)
Instruction 1
Instruction 2
Instruction 3
Instruction 4
Pipeline
Decoder
Decoder
Decoder
WB Unit
Scheduler
EX Unit
Re Order
Buffer
Out of Order EU
Intel NetBurst MicroArchitecture
Instruction 1
Instruction 2
Instruction 3
Instruction 4
Decoder
Decoder
Decoder
Scheduler
EX Unit
Re Order
Buffer
WB Unit
Decoded Instructions
(Execution Trace Cache)
Pipeline
Out of Order EU
Tasks of superscalar processing
Parallel Parallel Preserving the
decoding instruction sequential
and issue execution consistency of
instruction execution
and
exception processing
Superscalar decode and issue
I - cache
Instruction
buffer
Decode & Issue
IF
D/I
I - cache
Instruction
buffer
Decode & Issue
IF
D
I
Scalar
Issue
Superscalar
Issue
IF
D
I
IF
D
I
Parallel Decoding
Dependent/Independent Instructions
Read After Write (RAW), W after W, W after R
RAW (Ins2-Ins3): True dependency
WAW, WAR (Ins1 ot Ins3) : false dependency
Issue vs Dispatch
Blocking Issue
Instructions may be blocked due to data dependency
Non-blocking Issue
Instructions are not blocked due to data dependency
Blocking Issue
EU
EU
EU
Decode
Check & Issue
Instruction
Buffer
issue window
Non-blocking (shelved) Issue
Reservation
station
Dep. Checking/
dispatch
EU
Reservation
station
Dep. Checking/
dispatch
EU
Reservation
station
Dep. Checking/
dispatch
EU
Decode & Issue
Instruction
buffer
Handling of Issue Blockages
Preserving issue order Alignment of instruction issue
aligned unaligned
in-order out of order
Dependent/Independent Instructions
Issue Order
c
d
a
b
e
a
Issue window
Instructions
to be issued
Instructions
issued
c
d
a
b
e
a
Issue window
Instructions
to be issued
Instructions
issued
Issue in strict program order
Out of order Issue
c
Example: MC 88110, PowerPC 601
Independent instruction
Dependent instruction
Issued instruction
Alignment
c
d
a
b
e
a
fixed window
checked
in cycle 1
Aligned Issue
Unaligned Issue
issued
in cycle 1
f
g
h
next window
c
d
b
e
b
checked
in cycle 2
issued
in cycle 2
f
g
h
d
e
d
checked
in cycle 3
issued
in cycle 3
f
g
h
c
c
d
a
b
e
a
gliding window
f
g
h
c
d
b
e
b
f
g
h
d
e
f
g
h
c
d
e
f
Design choices in instruction issue
Coping with Coping with Use of Handling of Issue
false data unresolved shelving issue blockages rate
dependencies control (2-6)
dependencies
no Register
renaming
wait speculative
blocking shelved
Layout of Shelving Buffers
Type of the Number of Number of read
shelving buffers shelving buffer entries and write ports
Stand combined with
alone renaming and
(RS) reordering
individual 2-4
group 6-16
central 20
total 15-40
depends on
no. of EUs
connected
Reservation Stations (RS)
EU
EU
EU
EU
EU
EU
EU
EU
RS
RS
RS
RS
RS
Individual RSs
Group RSs
Central RS
Issue bound operand fetch�(with single register file)
EU
EU
RS
RS
EU
EU
RS
RS
Decode/issue
RF
instruction
data
Dispatch bound operand fetch (with single register file)
EU
EU
RS
RS
EU
EU
RS
RS
Decode/issue
instruction
data
RF
Why Renaming and Reordering?
RAW, WAR and WAW�(in Superscalar)
IF
IS
DP
EX
WB
IF
IS
DP
EX
WB
IF
IS
DP
EX
WB
write
read
write
RAW
WAR
WAW
Register renaming
write R5
RAW
read R5
WAR
write R5
RAW
read R5
write R5
RAW
read R5
write R8
RAW
read R8
Who does renaming?
X86 Assembly language program
8086 Registers
AH
AL
BH
BL
CH
CL
DH
DL
SI (Source Idx )
DI (Dest. Idx)
BP (Base Ptr )
SP (Stack Ptr)
CS (Code Seg Reg)
DS (Data Seg Reg )
ES (Extra Seg Reg )
SS (Stack Seg Reg)
IP (Intr Ptr)
Z (Flag Reg)
i386/i486/i686 Registers
AH
AL
BH
BL
CH
CL
DH
DL
SI (Source Idx )
DI (Dest. Idx)
BP (Base Ptr )
SP (Stack Ptr)
CS (Code Seg Reg)
DS (Data Seg Reg )
ES (Extra Seg Reg )
SS (Stack Seg Reg)
IP (Intr Ptr)
Z (Flag Reg)
EAX
EBX
ECX
EDX
ESI
EDI
EBP
ESP
ECS
EDS
EES
ESS
EIP
EZ
31 15 7 0
Extended
Memory layout of C program
Data
Code
Heap
Stack
BSS
Memory layout of C program
int A;
int B=10;
main(){
int Alocal;
int *p;
p=(int*)malloc(10);
}
Data
Code
Heap
Stack
BSS
MASM : Hello world
.model small
.stack 100h ; reserve 256 bytes of stack space
.data
message db "Hello world, I'm learning Assembly$”
.code
main proc
mov ax, seg message
mov ds, ax
mov ah, 09 // 9 in the AH reg indicates Procedure
//should write a bit-string to the screen.
lea dx, message // Load Eff Address
int 21h
mov ax,4c00h // Halt for DOS routine (Exit Program)
int 21h
main endp
end main
Memory Model: Segment Definition
Data Allocation Directives
.data
db A 100 dup (?) ; define 100 bytes, with no initial values for bytes
db “Hello” ; define 5 bytes, ASCII equivalent of “Hello”.
dd PtrArray 4 dup (?) ;array[0..3] of dword
maxint equ 32767 ; define maxint=32767
count equ 10 * 20 ; calculate a value (200)
MASM: Loop
MOV CX,100
_LABEL: INC AX
LOOP _LABEL
MOV CX,10
_CMPLOOP: DEC AX
CMP AX,3
LOOPNE CMPLOOP
MASM: Nested Loop
mov cx, 8
Loop1: push cx
mov cx, 4
Loop2: stmts
loop Loop2
pop cx
stmts
loop Loop1
Next Class Agenda
Thanks