Microprocessor and Programming
Microprocessor and Programming
1
Basics of
Microprocessor
8085
Memory
basics
To address any
location or to
select any
location we
require
address lines.
No of address
lines =
Control inputs
Data input
lines used for
DATA BUS
writing
operation
Address lines
1/15/16
No. of
locations =M
Eg: 3 bit address lines
are therefore = 8
locations and address
varies as:
000
001
010
111
and at every location
8 bit data present
BY UBAID SAUDAGAR
Therefore,
A microprocessor is an integrated circuit on a tiny silicon chip that contains thousands or
millions of tiny on/off switches, known as transistors.
The transistors are laid out such that they store or manipulate data. These circuits
manipulate data in certain patterns, patterns that can be programmed by software to
make machines do many useful tasks.
One of the biggest tasks microprocessors perform is acting as the brains inside a personal
computer. The number of transistors on a chip has grown from 2,300 on the 4004 in 1971
to 5.5 million on today's Pentium Pro processor. These advances have made today's
microprocessors 1,000 faster than their predecessors.
1/15/16
BY UBAID SAUDAGAR
Ports
Memory
1/15/16
BY UBAID SAUDAGAR
8085 Microprocessor
1/15/16
BY UBAID SAUDAGAR
BY UBAID SAUDAGAR
ARCHITECTURE OF 8085
The internal hardware design of the p
is called the Architecture of that p.
1/15/16
BY UBAID SAUDAGAR
Register Organization
In the architecture above we see many registers. The basic use of the register is temporary storage of
data.
But there are also some registers which are used for special purpose as well which will be defined later.
There are some registers which are accessible to the user and some are those which are not accessible to
the user.
Since the microprocessor is an 8 bit microprocessor hence all the general purpose registers are 8 bit in
size. It means that it can store 8 bit data.
These are six general purpose registers namely B,C,D,E,H,L all 8 bit in size.
They are used in general to store 8 bit data temporarily. Sometimes during calculations to
store the intermediate value, sometimes to store the result of any calculations etc.
These six registers can also be used to store 16 bit data by using them in pairs as BC, DE, HL.
When used in pairs they are also used to store addresses of memory locations which are 16 bits.
1/15/16
BY UBAID SAUDAGAR
10
1/15/16
BY UBAID SAUDAGAR
12
BY UBAID SAUDAGAR
13
1/15/16
BY UBAID SAUDAGAR
14
AD bus
Control bus
Microprocess
or
2000: 32H
2001: 3EH
2002: 47H
Memory
BY UBAID SAUDAGAR
15
1/15/16
BY UBAID SAUDAGAR
16
and 01H. Now this 20H is called as upper address or higher order
address and 01H is called as lower order address.
The higher order address from the address buffer (1) is transferred to the higher order address bus and the lower
order address from the address buffer (2) is transferred to the multiplexed lower order address/data bus.
The ALE signal from the timing and control unit goes high making address available on the multiplexed AD bus.
Both the addresses gets transferred on the address bus and the particular memory location is selected.
After that the data on that particular location is transferred on the multiplexed AD bus which is 8 bit wide. The
ALE signal now goes low i.e. ALE = 0 and the data from the memory now gets transferred from the memory to
the microprocessor.
1/15/16
BY UBAID SAUDAGAR
17
BY UBAID SAUDAGAR
18
1/15/16
BY UBAID SAUDAGAR
19
BY UBAID SAUDAGAR
20
1/15/16
BY UBAID SAUDAGAR
21
Interrupt control
Interrupts are those which break the normal sequence of operation of the microprocessor.
There are 6 hardware interrupts out of which 5 are input and one output interrupt pin.
There are maskable and nonmaskable interrupts.
Maskable interrupts are those which can be avoided.
Eg. Mobile phone, when the phone bell rings, if I am busy I can avoid the phone call by not picking it up.
Similarly when an interrupt which is maskable arrives at the microprocessor, if the microprocessor is busy it can avoid
this interrupt and respond to it at any other time.
Non maskable interrupts are those which cannot be avoided.
Eg. Smoke detector mounted on the ceiling of a classroom. It has to detect the smoke anyhow and cannot avoid it.
Similarly when a non maskable interrupt arrives at the microprocessor It cannot be avoided, the microprocessor stops its
current task and responds to the interrupt.
1/15/16
BY UBAID SAUDAGAR
22
Serial IO control
To transfer the data and receive data serially to and from the microprocessor, serial io control is used with two
pins namely SID and SOD.
These pins are used when microprocessor needs to communicate with any device serially or in other words
during serial communication where data is transferred is transferred to and from the microprocessor in serial form
(Bit by bit).
Serial i/p data and Serial o/p data for receiving and transferring data serially.
1/15/16
BY UBAID SAUDAGAR
23
Lower nibble
Higher nibble
BY UBAID SAUDAGAR
24
1/15/16
BY UBAID SAUDAGAR
25
1/15/16
BY UBAID SAUDAGAR
26
Chapter No.2
16 bit
Microprocessor
8086
BY UBAID SAUDAGAR
28
BY UBAID SAUDAGAR
29
Memory
BY UBAID SAUDAGAR
30
Architecture of 8086
U:
s out addresses
es instructions and data from memory
s the ports
words all operations related to outside world (outside the p) are handled by the BIU
ata transfers and address transfers are handled by this unit for BIU.
d Bus interface unit itself indicates that this unit is used to interface the buses with the outside w
BY UBAID SAUDAGAR
31
BIU
Memory
Interface
20
ARCHITECTURE
6
5
4
DS
ES
Segment Registers
--------
CS
6 byte
instruction
queue register
---------------------------------INSTRUCTION
DECODER AND
IP
Instruction pointer
CONTROL UNIT
-------------------------------------------------------INTERNAL SYSTEM BUSES
SS
AH
AL
BH
BL
CH
CL
DH
DL
General purpose
Registers
ARITHMETIC LOGIC
UNIT (ALU)
SP
BP
SI
EU
1/15/16
DI
TEMPORARY
REGISTER
FLAG REGISTER
BY UBAID SAUDAGAR
32
BY UBAID SAUDAGAR
33
EU (Execution Unit)
The execution unit consist of the following modules:
1. General purpose registers (They are used for multipurpose)
2. Pointers and index registers (As offset registers to select a particular location within a segment)
3. Arithmetic logic unit (ALU)
4. Operand register or temporary register ()
5. Flag register
6. Instruction decoder
7. Timing and control unit
With the help of these modules the following actions are performed:
-. The instruction bytes coming from the queue are decoded by the instruction decoder (here we come to
know two things : (1). How many bytes instruction (2). What operation is to be performed (by decoding
the opcode))
-. After decoding execution takes place and data is placed in proper registers or send to the BIU to save in
the memory
1/15/16
BY UBAID SAUDAGAR
34
0 AL
CH
CL
DH
DL
To store every bit 1 f/f is used hence an 8 bit register is used to store 8 bits and to store
BH
BL
16 bits, 16 bit register is used.
1/15/16
BY UBAID SAUDAGAR
36
BY UBAID SAUDAGAR
37
Segment registers
There are 4 segment registers in the Bus interface unit, size of each segment register is 16 bits.
15
0
Code Segment Register (CS register)
Code segment register (CS)
Data Segment Register (DS register)
Data segment register (DS)
Extra Segment Register (ES register)
Extra segment register (ES)
Stack Segment Register (SS register)
Stack segment register (SS)
The entire memory can be divided into four segments
- Code segment (Used to store instruction codes of the program)
- Data segment (Used to store data bytes/words)
- Extra segment (It is an additional segment to store data)
- Stack segment (Its used to store stack of data and addresses of main program during subroutine call)
Segment registers give the base address (starting address) to select any memory segment.
1/15/16
BY UBAID SAUDAGAR
38
Segment registers
Segment registers
CS
2500H
DS
4000H
ES
5000H
SS
7654H
Base
addrese
s
1/15/16
Code segment
0000H
1 MB
memory
FFFFH
Data segment
0000H
FFFFH
Extra segment
0000H
FFFFH
Stack segment
0000H
BY UBAID SAUDAGAR
39
1/15/16
BY UBAID SAUDAGAR
40
BY UBAID SAUDAGAR
41
1000
H
IP 2FACH
PA = BA + EA = 20 bits =
12FACH
Code
segment
-
8086
Memory
Microprocessor
1/15/16
BY UBAID SAUDAGAR
FFFFFH
42
Initial
The stack segment register and the stack pointer
register together
address the stack
top.
stack
0000H
1000H
Stack
top
segment
SS BA
PA = BA + EA = 10000H
Top of stack
FFFCH
SP OA
+ FFFCH = 1FFFCH
25
FFFDH
00
Microprocessor
98
34
1/15/16
BY UBAID SAUDAGAR
FFFEH
FFFFH
43
Stack memory
The stack in the 8086/8088 microprocessor, like that in many microprocessors, is a region of memory
that can store information for later retrieval. It is called a stack, because you "stack" things on it. The
philosophy is that you retrieve (pop) things in the opposite order of storing (push) them.
While executing main program you require some instructions which need to be executed again and
again within the same program, so instead of writing the same set of instructions again and again we
write a sub program or subroutine and then we call that subroutine from the main program.
So when we call the subroutine the address on the address bus changes as the control now gets
transferred to a different program. Therefore to avoid loss of address of main program we store this
address in a memory called as stack memory.
Now when the control gets transferred from main program to sub program the address on the address
bus changes. After executing the subroutine the address of the main program is required which is
stored in the stack memory.
This address is then again popped from the stack memory, and control gets transferred to main
program.
1/15/16
BY UBAID SAUDAGAR
44
Stack concept
SS = BA =
1000H
But if SP is loaded
initially = 1000H and
then PUSH inst. Is
executed then data
storage starts from
0FFFH and then
points to data last
entered i.e. 0FFEH
3AH
0000H
5DH
0FFEH
6FH
0FFFH
8BH
1000H
3EH
FFFEH
2CH
FFFFH
STACK SEGMENT
64 Kb
AX =
PUSH AX when SP =
2C3EH
0000H
1/15/16
Offset address
varies from 0000H
to FFFFH
AX =
6F5DH
PUSH AX when SP =
1000H
Initially SP = 0000H
When PUSH inst. Is
executed storage of
data starts from 1
less i.e. FFFFH and
then points to the
data last entered i.e.
FFFEH
BY UBAID SAUDAGAR
STACK SEGMENT
64 Kb
45
push ax
a dw 2500h
push bx
b dw 3498h
mov ax,0000
data ends
mov bx,0000
code segment
pop cx
start:
pop dx
int 3
mov ds, ax
mov ax,0000h
code ends
mov ax, a
end start
mov bx, b
1/15/16
BY UBAID SAUDAGAR
46
1/15/16
BY UBAID SAUDAGAR
47
- - - - - - - -
BA
OA
EA
0 0 1 1 0 1 1 0010H
1
PA = SS + BP = 00000H +
0010H = 00010H
- - - - - - - - - - - - - - 0 1 0 1 0 1 1 FFFCH
0
- - - - - - - -
Microprocess
or
1/15/16
1 0 0 1 1 0 0 FFFFH
0
BY UBAID SAUDAGAR
48
BA
OA
DI
EA
BX
EA
PA = DS + (SI or DI or BX)
= 10000H + 2000H = 12000H
or
= 10000H + 3000H = 13000H
or
= 10000H + 4000H = 14000H
processor
1/15/16
2000H
3000H
4000H
FFFFH
BY UBAID SAUDAGAR
49
Bit
15
X
Bit
14
X
Bit
13
X
Bit
12
OF
Bit
11
DF
Bit
10
IF
SF
8 MSBs
X Indicates Intel reserved (for future use)
CF Carry Flag
PF Parity Flag
AC Auxiliary Carry Flag
ZF Zero Flag
SF Sign Flag
TF Trap Flag
IF Interrupt Flag
DF Direction Flag
OF Overflow Flag
1/15/16
Total 9
flags
ZF
AC
PF
CF
8 LSBs
50
which is reflected by
the carry
flagthe two contents: 1001 0101
When
we add
AL register
+ 0110 1111
1/15/16
BY UBAID SAUDAGAR
51
1/15/16
BY UBAID SAUDAGAR
52
BY UBAID SAUDAGAR
53
BY UBAID SAUDAGAR
54
= 1010 0000
1/15/16
BY UBAID SAUDAGAR
55
Borrow taken
from the
higher nibble
1000
As we see above that a borrow is taken from the higher nibble. As soon as the borrow is
taken from the higher nibble the AC flag sets i.e. AC = 1
1/15/16
BY UBAID SAUDAGAR
56
p checks
these 8 bits
BX = 2008H
ADD AX,BX instruction is executed. The result obtained is 300AH (0011 0000 0000 1010) which is stored in
AX register.
Now p will check only the last 8 bits of the result
Here It came to know that No. of 1s are 2 which is even hence PF = 1
1/15/16
BY UBAID SAUDAGAR
57
1/15/16
BY UBAID SAUDAGAR
58
This borrow
SUB
comes from
1 AL,BL instruction is executed
sign flag
111 1 1
AL = 94H = 1 0 0 1 0 1 0 0
11110 011 0 1 1 0
BL = 96H1 =
SUB
= 1 1 1 1 1 1 1 0 = FEH
1/15/16
BY UBAID SAUDAGAR
59
1/15/16
BY UBAID SAUDAGAR
60
ADD AL,BL instruction is executed and the result will be by default stored in the AL
= 8 bits hence when a carry
register (size of AL = 8 bits)
is generated form the MSB
AL = 89H = 1000 1001
BL = 89H = 1000 1001
1/15/16
BY UBAID SAUDAGAR
61
INTR pin
To INTR circuit
IF
Shown above is the internal circuitry to control the maskable interrupts. When Bit 10 of Flag register is 0 i.e.
IF = 0, input to the AND gate is 0 therefore o/p of AND gate goes low. Therefore any input to the AND gate
wont be recognized hence any interrupt occurring on the INTR pin wont be acknowledged as it is not
recognized.
When IF = 1 and interrupt on the INTR pin occurs it is recognized and given to the internal INTR circuitry
through AND gate and then acknowledged.
1/15/16
BY UBAID SAUDAGAR
62
DS : 0000
40H
ES : 0000
DS : 0001
53H
ES : 0001
DS : 0002
87H
Memor
y
block
ES : 0002
Offset
ES : 0003
DS : 0003 98H
address
placed in DI
register
In the above example we see two memory blocks. The offset address of first memory block is
placed in the SI register and offset address of the second memory block is placed in the DI register.
Now we need to manually increment SI and DI after each byte transfer from data segment to extra
segment.
1/15/16
BY UBAID SAUDAGAR
64
OA
OA
65
BY UBAID SAUDAGAR
66
1/15/16
BY UBAID SAUDAGAR
67
1001H
Random
address
Memory
1/15/16
BY UBAID SAUDAGAR
68
1/15/16
BY UBAID SAUDAGAR
69
1/15/16
BY UBAID SAUDAGAR
70
M2
M3
M4
M5
0.2sec
(T1)
This is called
as parallel
processing
0.2sec
(T2)
0.2sec
(T1)
0.2sec
(T3)
0.2sec
(T2)
0.2sec
(T1)
0.2sec
(T4)
0.2sec
(T3)
0.2sec
(T2)
0.2sec
(T1)
0.2sec
0.2sec
0.2sec
0.2sec
0.2sec
1 person can do the work (T5)
in 1 sec, now
but
first time all the
(T4) the work
(T3) got divided,
(T2)
(T1)
(T7)
(T6)
(T5)
BY UBAID SAUDAGAR
(T4)
(T3)
71
First in
first out
Byte 2
Byte 1
To execution unit (For Decoding and Execution)
1/15/16
BY UBAID SAUDAGAR
72
BY UBAID SAUDAGAR
73
Address at which it is
3000H : JMP 8000
going to jump
The
BIU fetches inst. from the memory and keeps in the queue, it fetches 6 bytes
Address at
which
and keeps in the queue.
instruction lies
4CH
Memory
00H
3000H
3001H
80H
3002H
56H
3003H
67H
3004H
7AH
3005H
69H
7AH
Assuming
that 4CH is
opcode for
JUMP instr.
67H
56H
80H
00H
4CH
TO EXECUTION UNIT
1/15/16
BY UBAID SAUDAGAR
74
1/15/16
BY UBAID SAUDAGAR
75
What is pipelining ?
When one instruction is getting decoded and executed and simultaneously next instruction is being
fetched from the memory is called as pipelining process.
In 8086 with the help of queue register 6 instruction bytes are prefetched in the queue register, whenever
the EU requires bytes for decoding and execution purpose it just has to fetch from the queue register
instead of going to the main memory and waist its time.
By the time it is decoding and executing the byte fetched from the queue, p does not allow the buses to
remain idle, the external bus goes to the memory and fetches the next bytes and places in the queue.
This is actually parallel processing and similar to a water pipe where the water continues to remain in
motion. Similar way the instruction bytes are in continuous motion i.e. from the memory to the BIU then
into the queue then to the execution unit for execution.
In other words the motion of bytes does not stop anywhere ideally unless and until a branch instruction
arises in the queue.
Note: The p does not perform the next fetch operation till at least two bytes of the instruction queue are
emptied.
1/15/16
BY UBAID SAUDAGAR
76
Pipelining process
Here we can see that there
Is a pipeline structure
Memory
BIU
Execution unit
6
5
4
3
2
1
6 bytes queue
1/15/16
BY UBAID SAUDAGAR
77
1/15/16
BY UBAID SAUDAGAR
78
40
1
20
CLK
RESET
READY
19
21
22
NMI
INTR
17
18
TEST
MN/MX
1/15/16
16 -2, 39
38 - 35
/-/
8086
p
23
33
BY UBAID SAUDAGAR
34
32
BHE/
RD
31
30
29
26
27
28
25
24
Minimum
mode
pins
Maximum
mode pins
HOLD
HLDA
WR
DEN
DT/R
M/ IO
ALE
INTA
/
/
LOCK
79
Pin configuration
8086 is 16 bit p available in three clock rates 5, 8, and 10 MHz and is a 40 pin ic.
It works in two modes minimum mode and maximum mode.
The pins on the p 8086 can be categorized into 3 types:
1. Pins common to minimum and maximum mode
2. Minimum mode pins
3. Maximum mode pins
1/15/16
BY UBAID SAUDAGAR
80
(Pin 16 - 2) - Multiplexed
Address Data Bus
From pin number 16 2 are used by the multiplexed address data bus.
Multiplexing address and data lines means that the same lines are used for address and
data. Therefore the same lines are used to carry address information as well as data.
During T1 state of every machine cycle ALE signal goes high and enables the latches,
during this T1 state address which is generated by the p is available on this multiplexed
bus.
After T1 state gets over ALE signal goes low which disables the latches and DEN signal
also goes low which enables the Transrecievers. Now data is available on the multiplexed
bus.
Refer concept of latch
1/15/16
BY UBAID SAUDAGAR
81
- (Pin 38 35)
These lines work as Address Bus (A16 A19) during T1 state of every machine cycle i.e.
when ALE signal goes high.
T2 onwards these work as status signals S3 to S6
S3 and S4 gives the status of the memory segment currently accessed.
S5 gives the status of Interrupt Flag.
S6 remains low in general.
Segment accessed
1/15/16
Extra segment
Stack segment
Code segment
Data segment
BY UBAID SAUDAGAR
82
Interrupt basics
What is an interrupt?
An interrupt is an external signal to the p which breaks the normal sequence of the program running in
the p.
For Eg. A person is reading a book and while reading he hears the door bell so what he does is that he
puts a bookmark in the book and goes and opens the door, receives the request from the person standing
on the door and then comes back.
Now it depends who has arrived on the door, if a non important person is there then he can tell him to
wait or ignore. But if an imp. person is there whom he cannot avoid, then he has to compulsory respond.
Similarly there are two types of interrupts one maskable (can be avoided) and the other non maskable
(cannot be avoided)
Another Eg. Is of gas detector (at any how it is going to detect the gas (non - maskable)), and a mobile
phone (if a non important call is there user can avoid it and if an important call is there user will accept it)
p 8086 consist of two interrupt pins i.e. NMI and INTR and one acknowledge pin INTA
Instead of being wired directly to the CPU, the interrupts from the external devices are channeled through
Programmable interrupt controller (PIC 8259).
1/15/16
BY UBAID SAUDAGAR
83
1/15/16
BY UBAID SAUDAGAR
84
BY UBAID SAUDAGAR
85
1/15/16
BY UBAID SAUDAGAR
86
1/15/16
BY UBAID SAUDAGAR
87
RD
OE (o/p
enable)
Microprocess
Memory
or
Data from the memory goes to the p
1/15/16
BY UBAID SAUDAGAR
88
chmitt trigger
IC 8284
onverting sine wave
Clock generator
nto square wave
T
f/f
X2
X1
CLK
Microprocessor
Crystal oscillator
1/15/16
BY UBAID SAUDAGAR
1/15/16
BY UBAID SAUDAGAR
91
BY UBAID SAUDAGAR
92
Concept of latch
As we have learned the concept of f/f . What we have noticed that in some f/fs that
whatever we give them the input they store that input at their o/p.
A simple example is of a D f/f, where when we apply a logic 1 at its input that logic 1
appears at the o/p and doesnt change unless and until next clock appears.
Logic 0 at i/p
CLK
1/15/16
Logic 0 at o/p
Flip Flop or
Latch
BY UBAID SAUDAGAR
93
Concept of latch
So in general what we can say that it stores that 1 bit at its o/p or it holds this value at its
o/p, therefore we can also term it as a D latch.
A latch is nothing but a f/f but basically used to hold values at its o/p for other devices.
Now an Octal (Eight) Latch is a device with eight D f/fs.
Its IC number is 8282 . It has an i/p pin STB which is active high and when logic 1 is applied
to it activates the IC and i/ps are applied to all the latches and correspondingly o/ps appear
at the o/p.
Now lets understand why we require octal latch:
No. of address lines = 20
No. of data lines = 16
Now these 16 lines are multiplexed with 16 address lines and these are time multiplexed.
1/15/16
BY UBAID SAUDAGAR
94
Concept of latch
Multiplexing address and data lines means that the same lines are used for address and
data.
Therefore the same lines are used to carry address information as well as data.
The remaining address lines are multiplexed with 4 status signals (S3 S6)
Lets understand this multiplexing with the help of a simple multiplexer diagram :
Address
Data
2 : 1 MUX
BY UBAID SAUDAGAR
95
-------
1 T state
= 0.2 sec
1/15/16
BY UBAID SAUDAGAR
96
STB
Three
the connection
- is as follows:
octal
/ - /(8 bit) latches are required,
8282
Multiplexed
Microprocesso Address
r
and
Data bus
1/15/16
STB
8282
STB
8282
BY UBAID SAUDAGAR
98
ALE
/-/
-
Microproces
sor
1/15/16
20 bit address
3EH
32H
Octal
latche
s
Data bus
BY UBAID SAUDAGAR
opcode
fetched
during first
machine
cycle
This is the
data fetched
during
second
machine
cycle
99
BY UBAID SAUDAGAR
100
BY UBAID SAUDAGAR
101
BY UBAID SAUDAGAR
102
1/15/16
BY UBAID SAUDAGAR
103
1/15/16
BY UBAID SAUDAGAR
104
BY UBAID SAUDAGAR
105
OVERVIEW :
1/15/16
0101 0110
0010 0011
0001 0010
Odd bank
BY UBAID SAUDAGAR
8 bit data
at every
location
106
No. of address lines required to access 512 Kb = ; where x is the no. of address lines
We replace x by 19 therefore = 524288 locations and at each location 1 byte = 524288 bytes == 512 Kb
Address Bus
Even Memory
Bank
Address Bus
Data Bus
Data Bus
1/15/16
Odd Memory
Bank
BY UBAID SAUDAGAR
107
A0
BHE
Even
Memory
Bank
Odd
Memory
Bank
CS
CS
Microprocessor
8086
1/15/16
BY UBAID SAUDAGAR
108
1/15/16
BY UBAID SAUDAGAR
109
A1
8
A1
7
A1
6
A1
5
A1
4
A1
3
A1
2
A1
1
A1
0
A9
A8
A7
A6
A5
A4
A3
A2
A1
A0
BH
E
A0
BHE
A1 A19
ADDRESS BUS
DO D7
1/15/16
00001H
3EH
4FH
00003H
4AH
5CH
00005H
9CH
00000H
00002H
00004H
6BH
8086
D8 D15
34H
FFFFFH
54H
FFFFEH
DATA BUS
ADDRESS BUS
DATA BUS
BY UBAID SAUDAGAR
110
From the above diagram and table what we see is that, the address lines are connected to
both the banks simultaneously.
The lower order data lines (D0 D7) are connected to lower memory bank and higher
order data lines (D8 D15) are connected to higher memory bank.
Consider the 1st row in the table, where we see that A0 and BHE, both are low
hence both the banks are enabled.
Now the address from A19 A1 = 0000000000000000000, this address will select the 0 th
location of both the banks, since both the banks are enabled data will be loaded to both
the memory banks in case of write operation or data will be loaded from both the memory
banks to the data buses in case of read operation.
Consider the 2nd row in the table, where we see that A0 is 0 and BHE is 1,
therefore lower bank is enabled and higher bank is disabled.
1/15/16
BY UBAID SAUDAGAR
111
1/15/16
BY UBAID SAUDAGAR
112
As we discussed before that our main aim of memory banking is that the microprocessor
should be able to access 16 bits i.e. 2 bytes i.e. 1 word at a time and process it in 1
machine cycle.
But depending upon instruction and address it accesses bytes or words.
Consider the table on next slide
1/15/16
BY UBAID SAUDAGAR
113
ADDRESS
DATA TYPE
BHE
A0
MACHINE
CYCLE
DATA LINES
USED
MOV AL,
[0000H]
0000H
BYTE
ONE
D0 D7
MOV AX,
[0000H]
0000H
WORD
ONE
D0 D15
MOV AL,
[0001H]
0001H
BYTE
ONE
D8 D15
WORD
0
1
MOV AX,
0001H
[0001H]
Byte
is accessed in one
machine cycle as this
instruction is accessing a
byte from even memory
location. Hence even
bank is enabled and odd
bank is disabled and
data is available on the
lower order data bus D0 D7
1/15/16
1
FIRST
D8 D15
0
D0 D7
Byte is accessed
in one SECOND
Word is accessed in two
machine cycle as this
machine cycles. This inst.
instruction is accessing
Is accessing a word
a byte from odd memory
starting from the odd
location. Hence odd
memory location hence in
the first machine cycle 1
bank is enabled and
byte is accessed from odd
even bank is disabled
bank, in the 2nd machine
and data is available on
cycle 2nd byte is accessed
the higher order data
from even bank
bus D8 D15
BY UBAID SAUDAGAR
114
1/15/16
BY UBAID SAUDAGAR
115
WR
WR
8086
Microprocess
Memory
or from the microprocessor goes to memory
Data
1/15/16
BY UBAID SAUDAGAR
116
8086
Microprocessor
1/15/16
OE
Data Bus
Memory
BY UBAID SAUDAGAR
117
8086
Microprocessor
1/15/16
BY UBAID SAUDAGAR
118
BY UBAID SAUDAGAR
119
REQ
DACK
System Bus
DMA
Controller
8257
Microprocessor
8086
1/15/16
System Bus
BY UBAID SAUDAGAR
I/O
device
Memory
120
1/15/16
BY UBAID SAUDAGAR
121
1/15/16
BY UBAID SAUDAGAR
122
Output
BY UBAID SAUDAGAR
123
BY UBAID SAUDAGAR
124
Output
In the above diagram we see an active high tri state buffer. When the enable i/p is high
the buffer acts normally i.e. allows i/p to appear at the o/p with an increase in current as
current1/15/16
is amplified.
BY UBAID SAUDAGAR
125
Output A Input A
Input BOutput B
Enable
Enable
As we know that data bus is bidirectional, hence we see that buffers are also bidirectional.
1/15/16
BY UBAID SAUDAGAR
126
127
BY UBAID SAUDAGAR
128
DEN
8286
Transreciev
er
Active
low
o/p
OE
Microprocessor
8086
1/15/16
Active
low i/p
8286
Transreciev
er
BY UBAID SAUDAGAR
129
DT/R
8286
Transreciev
er
1/15/16
8086
Microprocess
or
BY UBAID SAUDAGAR
130
1/15/16
Indication
Interrupt acknowledge
Halt
Code Access
Read memory
Write memory
Passive
BY UBAID SAUDAGAR
131
1/15/16
BY UBAID SAUDAGAR
132
(Pin 24 25)
QS stands for queue status. It means that outside the chip we come to know what is the
status of the queue register inside the microprocessor.
Lets understand from the table below:
Queue status
0
The instruction queue is empty, all registers are cleared due to branching
operation
1/15/16
BY UBAID SAUDAGAR
133
//
This signal works in the maximum mode when more than one processor is connected in
the system.
RQ stands for bus request. GT stands for bus grant.
0 has the higher priority than 1. It means that when two processors simultaneously asks
the 8086 to release the system bus, the processor which is connected at pin 31 will get
bus grant first then the one which is connected at pin 30.
The external processor will send a low signal as a request to the p to release the system
bus, the p will complete its current machine cycle and release the bus i.e. it will grant the
bus to the bus master by sending a low signal.
After using the system bus again the external bus master will send a low signal thereby
releasing back the system bus to the p.
1/15/16
BY UBAID SAUDAGAR
134
1/15/16
BY UBAID SAUDAGAR
135
1/15/16
BY UBAID SAUDAGAR
137
1/15/16
BY UBAID SAUDAGAR
138
1/15/16
BY UBAID SAUDAGAR
139
1/15/16
BY UBAID SAUDAGAR
140
BY UBAID SAUDAGAR
141
1/15/16
BY UBAID SAUDAGAR
142
1/15/16
BY UBAID SAUDAGAR
143
1/15/16
BY UBAID SAUDAGAR
144
1/15/16
BY UBAID SAUDAGAR
145
1/15/16
BY UBAID SAUDAGAR
146
1/15/16
BY UBAID SAUDAGAR
147
4 Gb address space
BY UBAID SAUDAGAR
148
Memory segmentation
The
p 8086 has 20 address lines therefore the number of memory locations it can
access is = 1048576 = 1 Mb.
Therefore consider the memory below:
0000 0001
(01H)
0010 0100
(24H)
1000 1111
(8FH)
1001 1010
1/15/16
(9AH)
149
BY UBAID SAUDAGAR
150
1st segment
2nd segment
64 Kb
8th segment
15th segment
BY UBAID SAUDAGAR
Memory is divided
into 16 segments
and size of every
segment is 64 Kb
= 65536 = 64 Kb
It means that in every segment
there are 65536 locations.
Now we have such 16 segments
and every segment has 65536
locations it means that the total
size of the memory is = 65536 *
16 = 1048576 = 1 Mb
151
Memory segmentation
Now these segments are logical segments, it means that there is no physical division
within the memory.
The segments can either be Code Segment, Data Segment, Extra Segment, Stack
segment.
Code segment : when a segment is assigned as code segment, it is used to store the
codes or instructions
Data Segment : when a segment is assigned as data segment, it is used to store data
used in the programs
Extra Segment : it is also another segment used to store data
Stack Segment : it is used to store stack of data and address of main program during
subroutine call
1/15/16
BY UBAID SAUDAGAR
152
BY UBAID SAUDAGAR
153
=
=
10000H
20 bit physical
3467H
address
BY UBAID SAUDAGAR
154
0000H
FFFFH
Physical
address varies
from 00000H
To FFFFFH
Starting
addresses
of
segments
1/15/16
5000H
0000H
FFFFH
6000H
0000H
FFFFH
F000H
0000H
FFFFH
BY UBAID SAUDAGAR
Physical
address
varies from
00000H to
0FFFFH
Physical
address
varies from
F0000H to
FFFFFH
64 Kb
155
BY UBAID SAUDAGAR
156
01FFH
-------------1257FH
--------------One important point to notice is that the offset address varies as 0000H to FFFFH in every
segment but the base address of every segment is different. Hence physical address
varies due to base address.
1/15/16
BY UBAID SAUDAGAR
157
2000H
20000H
2FFFFH
2001H
20010H
3000FH
2100H
21000H
30FFFH
AB00H
AB000H
BAFFFH
1234H
12340H
2233FH
1/15/16
BY UBAID SAUDAGAR
158
Chapter No. 3
8086 Instruction
Set
1/15/16
BY UBAID SAUDAGAR
159
BY UBAID SAUDAGAR
160
161
BY UBAID SAUDAGAR
162
Both opcode and data (operand) present in the instruction are in binary numbers, so
how to differentiate?
The p always interprets the first byte it fetches as opcode and second as operand
Eg. We tell the processor that our program begins at 2000h. The first code it fetches is
3Eh, when it decodes it knows that it is a 2 byte instruction, hence the second code i.e.
32h is a data byte. If we enter 06h instead of 32h then it will load 06 in the accumulator
instead
of 32
1/15/16
BY UBAID SAUDAGAR
163
The word length is defined as the no. of bits, the microprocessor recognizes and processes at a time.
As we know that our microprocessor is 16 bit microprocessor hence it recognizes 16 bits at a time.
What actually it means is that the number of binary combinations possible to pass on the data bus.
Since data bus is of 16 bits hence 16 binary bits can pass on it from :
0000 0000 0000 0000
Between these two limits the number of binary combinations are = 65536
1/15/16
BY UBAID SAUDAGAR
164
1/15/16
BY UBAID SAUDAGAR
165
Addressing modes
The different addressing modes are as follows:
1. Implicit addressing mode
2. Register addressing mode
3. Immediate addressing mode
4. Direct addressing mode
5. Register Indirect addressing mode
6. Register relative addressing mode
7. Based indexed addressing mode
8. Relative based indexed addressing mode
1/15/16
BY UBAID SAUDAGAR
166
;this instruction when executed will move immediate data 02h into the bl register
;this instruction when executed will move immediate data 0000h to the ax register
Always in an instruction the source and the destination size should be same, if source is 8 bits in size,
then destination should also be 8 bits.
1/15/16
BY UBAID SAUDAGAR
167
1/15/16
BY UBAID SAUDAGAR
168
If bl = 55h;
al = 00h
;this instruction is not valid as the size in bits of source and destination is
BY UBAID SAUDAGAR
169
or mov al,[di]
UBAID SAUDAGAR
170
;here bxBYand
di hold offset address where data is present
The above instruction will move the content at the memory location 100Ah which is
formed by adding si and displacement in al register.
Assume data at location DS : 100Ah = 56h
Therefore al = 56h after execution
Note: The
displacement may be 8 bit or BY16
bit
1/15/16
UBAID SAUDAGAR
171
This instruction will mov the data present at the memory location 308Bh into al register.
Lets assume al = 09h before execution and address 308Bh contains 8Ch data.
After execution al = 8Ch
1/15/16
BY UBAID SAUDAGAR
172
173
CLD
STD
1/15/16
BY UBAID SAUDAGAR
174
Assembler directives
Assembly language contains two types of statements
- Instructions
- Directives
Instructions are translated into machine code by the assembler which the processor
understands by decoding them. In other words instructions, instruct the processor to do a
particular task.
Directives are instructions to the assembler which help the assembler in the assembly
process and these directives are not translated into machine code.
Or
Statements that direct the assembler to do some special task
1/15/16
BY UBAID SAUDAGAR
175
BY UBAID SAUDAGAR
176
BY UBAID SAUDAGAR
177
BY UBAID SAUDAGAR
178
Assume directive
A S S U M E : assume logical segment name
The ASSUME directive is used to inform the assembler the names of the logical segments to
be assumed for different segments used in the program.
Eg: the statement ASSUME
CS : CODE directs the assembler that the machine
code(executable program) are available in a segment named CODE and hence CS register
is to be loaded with the segment address for the label CODE, while loading.
Eg: the statement ASSUME DS : DATA indicates to the assembler that the data items related
to the program are available in the logical segment named DATA, and DS register is to be
initialized by the segment address for data segment while loading
1/15/16
BY UBAID SAUDAGAR
179
BY UBAID SAUDAGAR
180
1/15/16
BY UBAID SAUDAGAR
181
1/15/16
BY UBAID SAUDAGAR
182
BY UBAID SAUDAGAR
183
1/15/16
BY UBAID SAUDAGAR
184
Even directive
This assembler directive informs the assembler to increment the memory location counter to the next even address
if it is not already at the even address.
As we know that mp 8086 is a 16 bit processor, therefore it can access a word in one machine cycle.
But the condition is that the word is located at an even address.
Eg:1005h is a word located at 2000h and 2001h
Which means that at:
2000h 10h
2001h 05h
Hence in such case we dont require an even directive.
But if the word is located at 2001h and 2002h
Then it means that:
2001h 10h
2002h 05h
Now to access this word it will take 2 machine cycles, hence to reduce the access time we use even directive
1/15/16
BY UBAID SAUDAGAR
185
Chapter No.3
Instruction set of
8086
1/15/16
8/16 bits
X
8/16 bits
Destinati
on
BY UBAID SAUDAGAR
187
Arithmetic instructions
Arithmetic instructions are used to perform different arithmetic operations in ALU.
1/15/16
BY UBAID SAUDAGAR
188
Source
Register
Register
Memory
Register
BY UBAID SAUDAGAR
189
BY UBAID SAUDAGAR
190
1/15/16
BY UBAID SAUDAGAR
191
AL = AL + 06 = 14h
AH = AH + 1 = 00h + 01h = 01h (note that AH should be zero to get correct result)
AL = AL AND 0FH = 14h AND 0fh = 04h
Therefore AH = 01h AL = 04h i.e. correct unpacked bcd result
1/15/16
BY UBAID SAUDAGAR
192
BY UBAID SAUDAGAR
193
1/15/16
AH = 04
AL = 08
]
]
BY UBAID SAUDAGAR
194
1/15/16
BY UBAID SAUDAGAR
195
BY UBAID SAUDAGAR
196
1/15/16
BY UBAID SAUDAGAR
197
1/15/16
BY UBAID SAUDAGAR
198
1/15/16
BY UBAID SAUDAGAR
199
XLAT
The XLAT instruction is used to translate a byte from one code to another code
The byte to be translated is put in the AL register.
There is a lookup table where a number of bytes are present
Eg. Data segment
Table db 00h,01h,04h,09h,16h,25h
a db 04
Data ends
Code segment
Mov al, a
Lea bx, table
Xlat
Code ends
1/15/16
BY UBAID SAUDAGAR
200
ALU
1/15/16
BY UBAID SAUDAGAR
201
BY UBAID SAUDAGAR
202
Source
Register
Register
Memory
Register
Register
Memory
Register/memory
Data
Register/memory
Segment register
Segment register
except CS
Register/memory
1/15/16
BY UBAID SAUDAGAR
203
1/15/16
BY UBAID SAUDAGAR
204
AH
X may be 0 or 1
As reserved by Intel
Refer testint.asm
1/15/16
BY UBAID SAUDAGAR
205
AH
X may be 0 or 1
As reserved by Intel
Refer testint.asm
Note: The value which is reserved by Intel cannot be changed or manipulated
Eg: if at bit no.6, Intel has reserved a 0, if we try to set that bit, it cannot be set.
1/15/16
BY UBAID SAUDAGAR
206
R
DS
Memory
1/15/16
BY UBAID SAUDAGAR
207
R
ES
Memory
1/15/16
BY UBAID SAUDAGAR
208
EA of
memory
16 bit register
1/15/16
BY UBAID SAUDAGAR
209
Destination
Source
Register
Register
Register
Memory
Memory
Register
Register/mem
ory
Data
BY UBAID SAUDAGAR
210
1/15/16
BY UBAID SAUDAGAR
211
Eg:
sub ax, bx
sub al, bl
Refer testing.asm
1/15/16
BY UBAID SAUDAGAR
212
1/15/16
BY UBAID SAUDAGAR
213
1/15/16
BY UBAID SAUDAGAR
214
1/15/16
BY UBAID SAUDAGAR
215
1/15/16
BY UBAID SAUDAGAR
216
BY UBAID SAUDAGAR
217
1/15/16
BY UBAID SAUDAGAR
218
DIV S (Division)
This instruction is used for division operation.
To understand this instruction lets take some examples.
Eg1.
DIV BL
The above instruction will divide AX/BL by default (where AX is dividend and BL is divisor)
In other words, whenever the source operand is a byte, the dividend is a word i.e. AX register
After division we get a quotient and a remainder, quotient is stored in AL register and remainder is
stored in AH register by default
Eg2.
DIV BX
The above instruction will divide DX-AX/BX by default (where DX-AX is dividend and BX is divisor)
1/15/16
BY UBAID SAUDAGAR
219
BY UBAID SAUDAGAR
220
BY UBAID SAUDAGAR
221
1/15/16
BY UBAID SAUDAGAR
222
Next
instructio
n
HLT
RET
CALL
1/15/16
BY UBAID SAUDAGAR
223
String instructions
REP
This is an instruction prefix, which can be used in string instructions.
It can be used with string instructions only.
It causes the instruction to be repeated CX no. of times.
After each execution the SI and DI registers are incremented or decremented by 1.
It is important that before we use the REP instruction prefix the following steps must be
carried out:
1. CX must be initialized to count value.
2. If auto incrementing is required, DF must be cleared using CLD instruction else set
using STD instruction.
1/15/16
BY UBAID SAUDAGAR
224
String instructions
MOVSB/MOVSW{move string}
It is used to transfer a word/byte from data segment to extra segment
The offset of the source in the data segment is in SI
The offset of the destination in extra segment is in DI
Eg: MOVSB {ES:[DI]
DS:[SI]..byte transfer}
1/15/16
DS:[SI],DS:[SI+1]}
BY UBAID SAUDAGAR
225
String instructions
2.LODSB/LODSW {Load string}
It is used to load AL(or AX) register with a byte(or word) from data segment.
The offset of the source in data segment is in SI
Eg: LODSB { AL
DS:[SI].byte transfer}
DS:[SI]; AH
1/15/16
DS:[SI+1]}
BY UBAID SAUDAGAR
226
String instructions
3.STOSB/STOSW {Store string}
It is used to store AL(or AX) in the extra segment.
The offset of the destination in extra segment is in DI
Eg: STOSB {ES:[DI]
Eg: STOSW {ES:[DI]
1/15/16
AL .byte transfer}
AL; ES:[DI+1]
AH}
BY UBAID SAUDAGAR
227
String instructions
4.CPMSB/CPMSW {Compare string}
It is used to compare a byte(or word) in the data segment with a byte or a word in the
extra segment
The offset of the byte(or word) in extra segment is in DI, the offset of the byte(or word) in
data segment is in SI
Comparison is done by subtracting the byte(or word) in extra segment from the byte(or
word) in data segment
Flags are affected but result is not stored anywhere
Eg: CMPSB {compare DS[SI]with ES:[DI].byte operation}
Eg: CMPSW {compare DS:[SI],DS:[SI+1] and ES:[DI],ES:[DI+1]}
1/15/16
BY UBAID SAUDAGAR
228
1/15/16
BY UBAID SAUDAGAR
229