Professional Documents
Culture Documents
ch-1 3
ch-1 3
ch-1 3
&
Assembly Language
Chapter 1
Registers
inside 8088/8086
Registers are used to store information temporarily.
That information could be one or two bytes of data to be processed or
the address of data.
The general-purpose registers in 8088/86 microprocessors can be
accessed as either 16-bit or 8-bit registers.
All other registers can be accessed only as the full 16 bits.
In the 8088/86. data types are either 8 or 16 bits. To access 12-bit data.
for example, a 16-bit register must be used with the highest 4 bits set
to 0.
Registers
inside 8088/8086
In the 8088/86. data types are either 8 or 16 bits.
To access 12-bit data. for example, a 16-bit register must
be used with the highest 4 bits set to 0.
16-bit Name
AX accumulator
AH - AL
AX
BX base
BH BL
BX
CX loop counter
CH CL
CX
DX data
DH DL
DX
SP stack pointer
SP
BP base pointer
BP
SI source index
SI
DI destination index
DI
CS code segment
CS
DS data segment
DS
SS stack segment
SS
ES extra segment
ES
instruction
IP instruction pointer
IP
Flag
FLAGS
FR
Category
General-Purpose
Pointer
Index
Segment
Registers
General-Purpose Registers
Used primarily for arithmetic and data movement
mov eax, 10
AL = lower 8 bits
AH = upper 8 bits
ESI, EDI, EBP, ESP have only
16-bit names for lower half
10
12
Next ...
IA-32 Registers
Instruction Execution Cycle
IA-32 Memory Management
13
Fetch-Execute Cycle
Each machine language instruction is first fetched from
the memory and stored in an Instruction Register (IR).
The address of the instruction to be fetched is stored in a
register called Program Counter or simply PC. In some
computers this register is called the Instruction Pointer
or IP.
After the instruction is fetched, the PC (or IP) is
incremented to point to the address of the next
instruction.
The fetched instruction is decoded (to determine what
needs to be done) and executed by the CPU.
14
Clock
synchronizes all CPU and BUS operations
machine (clock) cycle measures time of a
single operation
clock is used to trigger events
one cycle
1
0
15
Infnite Cycle
actions
Operand
Fetch
Execute
Writeback
Result
and
16
Instruction Fetch
Instruction Decode
Operand Fetch
Execute
Result Writeback
17
Pipelining
There are two ways to make the CPU process information faster:
increase the working frequency
or change the internal architecture of the CPU. (Pipelining)
Pipelining is allow the CPU to fetch and execute at the same time.
Pipelining in the 8088/86 by splitting the internal structure of the
microprocessor into two sections: the execution unit (EU) and the bus
interface unit (BIU).
These two sections work simultaneously. The BIU accesses memory
and peripherals while the EU executes instructions previously fetched.
This works only if the BIU keeps ahead of the EU; thus the BIU of the
8088/86 has a buffer, or queue.
The buffer is 4 bytes long in the 8088 and 6 bytes in the 8086.
If any instruction takes too long to execute, the queue is filled to its
maximum capacity and the buses will sit idle.
The BIU fetches a new instruction whenever the queue has room for 2
bytes in the 6-byte 8086 queue, and for 1 byte in the 4-byte 8088 queue.
18
19
Pipelined Execution
Cycles
Stages
1
2
3
4
5
6
7
8
9
10
11
12
S1
I-1
S2
S3
S4
S5
S6
I-1
No I-1
n- I-1
Wa
ex pipe I-1
ste ec
l
d c uti ined
I-2
loc on
kc
I-2
yc
I-2
les
I-2
I-1
Pipelined
Execution
I-2
I-2
20
Cycles
S1
I-1
I-2
I-3
S2
I-1
I-2
I-3
S3
I-1
I-2
I-3
exe
S4
I-1
I-1
I-2
I-2
I-3
I-3
S5
S6
I-1
I-1
I-2
I-2
I-3
I-3
21
Superscalar Architecture
Introduction to Assembly
Language
MOV instruction
MOV Examples
MOV
MOV
MOV
MOV
MOV
MOV
CL, 55H
DL, CL
AH, DL
AL, AH
BH, CL
CH, BH
MOV
MOV
MOV
MOV
MOV
MOV
MOV
MOV
CX, 468FH
AX, CX
DX, AX
BX, DX
DI, BX
SI, DI
DS, SI
BP, DI
24
MOV Instruction
Data can be moved among all the register as long as the source and
destination registers match in size.
MOV AL, DX; Error
Data can not be moved directly into segment registers.
MOV DS, 2459H
; Error
Values cannot be loaded directly into any segment register (CS, DS, ES, or
SS).
To load a value into a segment register, first load it to a nonsegment
register and then move it to the segment register.
MOV AX, 2345H
;Ioad 2345H into AX
MOV DS, AX
;load the value of AX into DS
If a value less than FFH is moved into a 16-bit register, the rest of the bits
are assumed to be all zeros.
MOV BX, 5 ;the result will be BX = 0005;
Moving a value that is too large into a register will cause an error.
MOV BL, 7F2H
;ILLEGAL: 7F2H is larger than 8 bits
MOV AX, 2FE456H ;ILLEGAL: the value is larger than AX
25
ADD instruction
ADD instruction has the following format:
ADD destination, source
The ADD instruction adds the source and destination operands and put
the result in the destination.
To add two numbers such as 25H and 34H:
MOV AL, 25H
;move 25 into AL
MOV BL, 34H
;move 34 into BL
ADD AL, BL
;AL = AL + BL
The program above can be written in many ways,
MOV DH, 25H
;move 25 into DH
MOV CL, 34H
;move 34 into CL
ADD DH, CL
;add CL to DH; DH = DH+CL
Another way:
MOV DH, 25H
ADD DH, 34H
ADD instruction
The largest number that an 8-bit register can hold is
FFH. To use numbers larger than FFH (255 decimal),
16-bit registers such as AX, BX, ex, or DX must be
used.
For example, to add two numbers such as 34EH and
6A5H, the following program can be used:
MOV AX, 34EH
;move 34EH into AX
MOV DX, 6ASH
;move 6A5H into DX
ADD DX, AX
;add AX to DX
Again, any 16-bit non segment registers could have
been used to perform the action above:
MOV CX, 34EH
;Ioad 34EH into CX
ADD CX, 6A5H
;add 6A5H to CX
27
28
Flag Register in
8086/8086
29
Status Flags
Status of arithmetic and logical operations
Programs can set and clear individual bits in the EFLAGS register
30
Status Flags
31
Example 1-10
Show how the flag register is affected by the addition of 38H and
2FH.
Solution
MOV BH, 38H
ADD BH, 2FH
;BH= 38H
;add 2F to BH, now BH=67H
111
38
+
67
0011
2F
0110
1000
0010
0111
1111
32
Example 1-11
Show how the flag register is affected by
MOV AL, 9CH
;AL = 9CH
MOV DH, 64H
;DH = 64H
ADD AL, DH
;now AL = 0
Solution
1 11 1
9C
64
1
00
1001 1100
0110 0100
1
0000 0000
33
The End
34