Module 3 Full
Module 3 Full
• Syllabus
• Stack structure of 8086,Programming using
stack.Interrupts - Types of Interrupts and Interrupt Service
Routine. Handling Interrupts in 8086, Interrupt
programming. - Programmable Interrupt Controller - 8259
– Architecture(Just mention the control word,no need to
memorize the control word)-Interfacingmemory with 8086.
CE kottarakkara,Dept. of CSE 2
• When an interrupt occurs, the 80x86
automatically PUSHes the current flags, the value
in CS, and the value in IP onto the stack. • As part
of the service routine for the interrupt, the
contents of other registers may be pushed onto
the stack by executing PUSH instructions.
CE kottarakkara,Dept. of CSE 3
• stack is implemented in the memory of the 8086.
• It is a maximum of 64K bytes long .The lowest
addressed byte in the current stack is pointed to
by the contents of the stack segment (SS) register.
• Another register, the stack pointer (SP) contains an
offset of the current top of the stack from the
value in SS.
• The address obtained from the contents of SS and
SP is the physical address of the last storage
location in the stack to which data were PUSHed.
This is known as the top of the stack.
CE kottarakkara,Dept. of CSE 4
• The value in the stack pointer starts at 0FFFFh upon
initialization of the 8086.
• Combining this value with the current value in SS
gives the highest addressed location in the stack: that
is, the bottom of the stack.
• Since data transfers to and from stack are always 16-
bit words, it is important to configure the system such
that all stack locations are at even word boundaries.
• This minimizes the number of memory cycles required
to PUSH or POP data for the stack and minimizes the
amount of time required to perform a switch in
program context.
CE kottarakkara,Dept. of CSE 5
• The 8086 PUSHes data and addresses to the
stack one word at a time.
Each time a register value is to be PUSHed onto
the top of the stack, the value in the stack pointer
is first decremented by 2 and then the contents of
the register are written into memory.
the stack grows down in memory from the bottom
of the stack, which corresponds to the physical
address derived from SS and 0FFFFh toward the
end of the stack, which corresponds to the
physical address obtained from SS and offset
000016.
CE kottarakkara,Dept. of CSE 6
• When a value is popped from the top of the stack,
the reverse of this sequence occurs. The physical
address defined by SS and SP always points to the
location of the last value pushed onto the stack.
• Its contents are first popped off the stack and put
into the specified register within the 8086; then SP
is incremented by 2. The top of the stack now
corresponds to the previous value pushed onto
the stack
CE kottarakkara,Dept. of CSE 7
PUSH operation
• For instance, if the instruction is PUSH AX its
execution results in the following:
• SP <- SP - 1 ; SP is decrementedSS:SP <= AH ; AH
is PUSHed on the Stack
• SP <- SP - 1 ; SP is decrementedSS:SP <= AL ; AL is
PUSHed on the Stack
CE kottarakkara,Dept. of CSE 8
Pop operation
• if the instruction is POP AX, its execution results in
the following:AL <- SS:SP ; AL is POPped from the
StackSP <- SP + 1 ; SP is incrementedAH <= SS:SP ;
AH is POPped from the StackSP <- SP + 1 ; SP is
incremented
CE kottarakkara,Dept. of CSE 9
Programming using stack
Interrupt N
Req
Accept N
Interrupt
Get interrupt
vector
Jump to ISR
Save PC
Load PC
INTR
INTA΄
D7-D0 Vector
D7
Peripheral
Device
8088 System
D0
A0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
E2 INTR
LS244
E1
I7 I6 I5 I4 I3 I2 I1 I0
A19 +5V
INTA
4C = 0 1 0 0 1 1 0 0
INTR
0 1 2 3 4 5 6 7 8 9 A B C D E F
00000 3C 22 10 38 6F 13 2C 2A 33 22 21 67 EE F1 32 25
00010 11 3C 32 88 90 16 44 32 14 30 42 58 30 36 34 66
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00100 4A 33 3C 4A AA 1A 1B A2 2A 33 3C 4A AA 1A 3E 77
00110 C1 58 4E C1 4F 11 66 F4 C5 58 4E 20 4F 11 F0 F4
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
00250 00 10 10 20 3F 26 33 3C 20 26 20 C1 3F 10 28 32
00260 20 4E 00 10 50 88 22 38 10 5A 38 10 4C 55 14 54
......... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
003E0 3A 10 45 2F 4E 33 6F 90 3A 44 37 43 3A 54 54 7F
003F0 22 3C 80 01 3C 4F 4E 88 22 3C 50 21 49 3F F4 65
CS305 MP-MC, Dept of CSE,College of
19
Engg,Kottarakkara
Interrupt Vector Table –Example
Write a sequence of instructions that initialize vector 40H to point to the ISR
“isr40”.
Answer: Address in table = 4 X 40H = 100H
Set ds to 0 since the Interrupt Vector Table begins at 00000H
Get the offset address of the ISR using the Offset directive
and store it in the addresses 100H and 101H
Get the segment address of the ISR using the Segment directive
and store it in the addresses 102H and 103H
push ax Save registers in the stack
push ds
mov ax,0
Set ds to 0 to point to the interrupt vector table
mov ds,ax
mov ax,offset isr40 Get the offset address of the ISR and store
mov [0100h],ax it in the address 0100h (4X40h = 100h)
mov ax,segment isr40 Get the segment address of the ISR
mov [0102h],ax and store it in the address 0102h
pop ds
Restore registers from the stack
pop ax
CS305 MP-MC, Dept of CSE,College of
20
Engg,Kottarakkara
Interrupt Masking
• The processor can inhibit certain types of
interrupts by use of a special interrupt mask bit.
• This mask bit is part of the flags/condition code
register, or a special interrupt register.
• If this bit is clear, and an interrupt request occurs
on the Interrupt Request input, it is ignored.
• NMI cannot be masked
• Exceptions:
– Divide by zero
– Memory protection fault
• Process interrupt
• Restore state
– Load PC, flags, registers etc.
input-signals
8259A
IRR output-signal
IMR
ISR
8259A
8259A INTR CPU
PIC
PIC (master)
(slave)
Programming is via
Programming is via I/O-ports 0x20-0x21
I/O-ports 0xA0-0xA1
Block Diagram(Architecture) of 8259
1 S7 S6 S5 S4 S3 S2 S1 S0 (master)
1 0 0 0 SFNMBUFM / SAEOIµPM
Input Buffer
Output buffer
• Enable Connections:
– All memory devices have at least one Chip Select (CS) or Chip Enable (CE)
input, used to select or enable the memory device.
• If a device is not selected or enabled then no data can be read from, or
written into it.
• The CS or CE input is usually controlled by the microprocessor through the
higher address lines via an address decoding circuit.
• Control Connections:
– RAM chips have two control input signals that specify the type of memory
operation: the Read (RD) and the Write (WR) signals.
• Some RAM chips have a common Read/ Write (R/W) signal.
– ROM chips can perform only memory read operations, thus there is no need
for a Write (WR) signal.
• In most real ROM devices the Read signal is called the Output Enable
(OE) signal. College of Engg,Kottarakkara,Dept. of CSE 43
Memory Read Operations
C hip E nable
R ead (R D )
C lo c k T1 T2 T3
A d d re s s B u s V a lid A d d r e s s
D a ta B u s V a lid D a t a
C h ip E n a b le
W r it e ( W R )
S te p 2
S te p 1 45
College of S te p 1 a S te p 3
S te p 4
Engg,Kottarakkara,Dept. of CSE
Example: (32X4 RAM module using 8X4 RAM chips - Assume an 8-address line processor)
D3 D3 D0 D3 D0 D3 D0 D3 D0
8x4 RAM 1 8x4 RAM 2 8x4 RAM 3 8x4 RAM 4
A0 A0 A0 A0
D0
A2 A2 A2 A2
RD WR CS RD WR CS RD WR CS RD WR CS
RD
WR
A0
2X4 DEC.
A2
A3 A Y0
A4 B Y1
A5 Y2
A6 CS Y3
A7
College of 46
Engg,Kottarakkara,Dept. of CSE
Memory Map for previous example.
There are three address lines connected on the address selection circuit. Thus
there can be eight different memory map configurations.
Three possible memory map configurations are shown below.
D7
D0 D7 D0 D7 D0 D7 D0 D7
D0 A0 A0 A0 A0
RD WR CS RD WR CS RD WR CS RD WR CS
RD
WR
A0
2X4 DEC.
A11
A Y0
A12
B Y1
A13
Y2
A14
CS Y3
A15 A15