Mic Module IV
Mic Module IV
Mic Module IV
If the stack top points to a memory location 52050 H, it means that the location
52050 H is already occupied, i.e. previously pushed data is available at 52050 H. The
next 16-bit push operation will decrement the stack pointer by two, so that it will point to
the new stack-top 5204EH, and the decremented contents of SP will be 204E H. this
location will now be occupied by the recently pushed data. Thus, if a 16-bit data is
pushed onto the stack, the push operation will decrement the SP by two because two
locations will be required for a 2-byte (16- bit) data. Hus it may be noted here that the
stack grows down.
Thus for a selected value of SS, the maximum value of SP = FFFF H and the
segment can have maximum of 64K locations. Thus after starting with an initial value of
FFFFH, the Stack Pointer (SP) is decremented by two, whenever a 16-bit data is
pushed onto the stack. After successive push operations, when the Stack Pointer
contains 0000 H, any attempt to further push the data to the stack will result in stack
overflow.
Each PUSH operation decrements the SP as explained above, while each POP
operation increments the SP. The POP operation is used to retrieve the data stored on
to the stack. Fig.5.12 shows the stack overflow conditions, while Fig.5.13 shows the
effect of PUSH and POP operations on the stack memory block.
Fig.4.6 ISR
Whenever a number of devices interrupt a CPU at a time, and if the processor is
able to handle them properly, it is said to have multiple interrupt processing capability.
For example, 8085 has five hardware interrupt pins and it is able to handle the
interrupts simultaneously under the control of software. In case of 8086, there are two
interrupt pins, viz. NMI and INTR. The NMI is a nonmaskable interrupt input pin which
means that any interrupt request at NMI input cannot be masked or disabled by any
means. The INTR interrupt, however, may be masked using the Interrupt Flag (IF). The
INTR, further, is of 256 types. The INTR types may be from 00 to FFH (or 00 to 255).
Hardware Interrupts
Hardware interrupt is caused by any peripheral device by sending a signal
through a specified pin to the microprocessor.
The 8086 has two hardware interrupt pins, i.e. NMI and INTR. NMI is a non-
maskable interrupt and INTR is a maskable interrupt having lower priority.
One more interrupt pin associated is INTA called interrupt acknowledge.
NMI
It is a single non-maskable interrupt pin (NMI) having higher priority than the
maskable interrupt request pin (INTR)and it is of type 2 interrupt.
When this interrupt is activated, these actions take place −
Completes the current instruction that is in progress.
Pushes the Flag register values on to the stack.
Pushes the CS (code segment) value and IP (instruction pointer) value
of the return address on to the stack.
IP is loaded from the contents of the word location 00008H.
CS is loaded from the contents of the next word location 0000AH.
Interrupt flag and trap flag are reset to 0.
INTR
The INTR is a maskable interrupt because the microprocessor will be
interrupted only if interrupts are enabled using set interrupt flag instruction. It
should not be enabled using clear interrupt Flag instruction.
The INTR interrupt is activated by an I/O port. If the interrupt is enabled and
NMI is disabled, then the microprocessor first completes the current
execution and sends ‘0’ on INTA pin twice. The first ‘0’ means INTA informs
the external device to get ready and during the second ‘0’ the microprocessor
receives the 8 bit, say X, from the programmable interrupt controller.
These actions are taken by the microprocessor −
First completes the current instruction.
Activates INTA output and receives the interrupt type, say X.
Flag register value, CS value of the return address and IP value of the
return address are pushed on to the stack.
IP value is loaded from the contents of word location X × 4
CS is loaded from the contents of the next word location.
Interrupt flag and trap flag is reset to 0
Software Interrupts
Some instructions are inserted at the desired position into the program to
create interrupts. These interrupt instructions can be used to test the working
of various interrupt handlers. It includes −
Broadly, there are two types of interrupts. The first out of them is external
interrupt and the second is internal interrupt. In external interrupt, an external device or
a signal interrupts the processor from outside or, in other words, the interrupt is
generated outside the processor, for example, a keyboard interrupt. The internal
interrupt, on the other hand, is generated internally by the processor circuit, or by the
execution of an interrupt instruction. The examples of this type are divide by zero
interrupt, overflow interrupt, interrupts due to INT instructions, etc.
Suppose an external device interrupts the CPU at the interrupt pin, either NMI or
INTR of the 8086, while the CPU is executing an instruction of a programme. The CPU
first completes the execution of the current instruction. The IP is then incremented to
point to the next instruction. The CPU then acknowledges the requesting device on its
pin immediately if it is a NMI, TRAP or Divide by Zero interrupt. If it is an INT
request, the CPU checks the IF flag. If the IF is set, the interrupt request is
acknowledged using the pin. If the IF is not set, the interrupt requests are ignored.
Note that the responses to the NMI, TRAP and Divide by Zero interrupt requests are
independent of the IF flag. After an interrupt is acknowledged, the CPU computes the
vector address from the type of the interrupt that may be passed to the interrupt
structure of the CPU internally (in case of software interrupts, NMI, TRAP and Divide by
Zero interrupts) or externally, i. e. from an interrupt controller in case of external
interrupts. (The contents of IP and CS are next pushed to the stack. The contents of IP
and CS now point to the address of the next instruction of the main programme from
which the execution is to be continued after executing the ISR. The PSW is also pushed
to the stack). The Interrupt Flag (IF) is cleared. The TF is also cleared, after every
response to the single step interrupt. The control is then transferred to the interrupt
service routine for serving the interrupting device. The new address of ISR is found out
from the interrupt vector table. The execution of the ISR starts. If further interrupts are to
be responded to during the time the first interrupt is being serviced, the IF should again
be set to 1 by the ISR of the first interrupt. If the interrupt flag is not set, the subsequent
interrupt signals will not be acknowledged by the processor, till the current one is
completed. The programmable interrupt controller is used for managing such multiple
interrupts based on their priorities. At the end of ISR the last instruction should be IRET.
When the CPU executes IRET, the contents of flags, IP and CS which were saved at
the start by the CALL instruction are now retrieved to the respective registers. The
execution continues onwards from this address, received by IP and CS.
We now discuss how the 8086/88 finds out the address of an ISR. Every external
and internal interrupt is assigned with a type (N), that is either implicit (in case of NMI,
TRAP ad Divide by Zero) or specified in the instruction INT N (in case of internal
interrupts). In case of external interrupts, the type is passed to the processor by an
external hardware like programmable interrupt controller. In the zeroth segment of
physical address space, i. e. CS = 0000, Intel has reserved 1,024 locations for storing
the interrupt vector table. The 8086 supports a total of 256 types of the interrupts, i. e.
from 00 to FFH. Each interrupt requires 4 bytes, i. e. two bytes each for IP and CS of its
ISR. Thus a total of 1,024 bytes are required for 256 interrupt types, hence the interrupt
vector table starts at location 0000:0000 and ends at 0000:03FFH. The interrupt vector
table contains the IP and CS of all the interrupt types stored sequentially from address
0000:0000 to 0000:03FFH. The interrupt type N is multiplied by 4 and the hexadecimal
multiplication obtained gives the offset address in the
zeroeth code segment at which the IP and CS addresses of the interrupt service routine
(ISR) are stored. The execution automatically starts from the new CS : IP.
Fig.5.14 shows the interrupt sequence o 8086/88 and Fig.5.15 shows the
structure of interrupt vector table.
Fig.5.14 Interrupt Response Sequence