cs401 Computer Architecture and Assembly Language, Lecture notes of Assembly Language Programming

cs401 Computer Architecture and Assembly Language

Typology: Lecture notes

2018/2019

Uploaded on 07/07/2019

ehsan412
ehsan412 🇵🇰

4 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Architecture & Assembly Language
Programming
Course Code: CS401
Virtual University of Pakistan 96
divide by zero interrupt. A list of all reserved interrupts is given later. Such
interrupts are programmed in the hardware to generate the designated
interrupt when the specied condition arises. The remaining interrupts are
provided by the processor for our use. Some of these were reserved by the
IBM PC designers to interface user programs with system software like DOS
and BIOS. This was the logical choice for them as interrupts provided a very
exible architecture. The remaining interrupts are totally free for use in user
software.
The correlation process from the interrupt number to the interrupt handler
uses a table called interrupt vector table. Its location is xed to physical
memory address zero. Each entry of the table is four bytes long containing
the segment and oset of the interrupt routine for the corresponding
interrupt number. The rst two bytes in the entry contain the oset and the
next two bytes contain the segment. The little endian rule of putting the more
signicant part (segment) at a higher address is seen here as well.
Mathematically oset of the interrupt n will be at nx4 while the segment will
be at nx4+2. One entry in this table is called a vector. If the vector is changed
for interrupt 0 then INT 0 will take execution to the new handler whose
address is now placed at those four bytes. INT 1 vector occupies location 4,
5, 6, and 7 and similarly vector for INT 2 occupies locations 8, 9, 10, and 11.
As the table is located in RAM it can be changed anytime. Immediately after
changing it the interrupt mapping is changed and now the interrupt will
result in execution of the new routine. This indirection gives the mechanism
extreme exibility.
The operation of interrupt is same whether it is the result of an INT
instruction (software interrupt) or it is generated by an external hardware
which passes the interrupt number by a dierent mechanism. The currently
executing instruction is completed, the current value of FLAGS is pushed on
the stack, then the current code segment is pushed, then the oset of the
next instruction is pushed. After this it automatically clears the trap ag and
the interrupt ag to disallow further interrupts until the current routine
nishes. After this it loads the word at nx4 in IP and the word at nx4+2 in CS
if interrupt n was generated. As soon as these values are loaded in CS and IP
execution goes to the start of the interrupt handler. When the handler
nishes its work it uses the IRET instruction to return to the caller. IRET
pops IP, then CS, and then FLAGS. The original value of IF and TF is
restored which re-enables further interrupts. IF and TF will be discussed in
detail in the discussion of real time interrupts. We have discussed three
things till now.
1. The INT and IRET instruction format and syntax
2. The formation of IVT (interrupt vector table)
3. Operation of the processor when an interrupt in generated
Just as discussed in the subroutines chapter, the processor will not match
interrupt calls to interrupt returns. If a RETF is used in the end of an ISR the
processor will still return to the caller but the FLAGS will remain on the
stack which will destroy the expectations of the caller with the stack. If we
pf2

Partial preview of the text

Download cs401 Computer Architecture and Assembly Language and more Lecture notes Assembly Language Programming in PDF only on Docsity!

Computer Architecture & Assembly Language Programming

Course Code: CS

[email protected]

Virtual University of Pakistan 96 divide by zero interrupt. A list of all reserved interrupts is given later. Such interrupts are programmed in the hardware to generate the designated interrupt when the specified condition arises. The remaining interrupts are provided by the processor for our use. Some of these were reserved by the IBM PC designers to interface user programs with system software like DOS and BIOS. This was the logical choice for them as interrupts provided a very flexible architecture. The remaining interrupts are totally free for use in user software. The correlation process from the interrupt number to the interrupt handler uses a table called interrupt vector table. Its location is fixed to physical memory address zero. Each entry of the table is four bytes long containing the segment and offset of the interrupt routine for the corresponding interrupt number. The first two bytes in the entry contain the offset and the next two bytes contain the segment. The little endian rule of putting the more significant part (segment) at a higher address is seen here as well. Mathematically offset of the interrupt n will be at nx4 while the segment will be at nx4+2. One entry in this table is called a vector. If the vector is changed for interrupt 0 then INT 0 will take execution to the new handler whose address is now placed at those four bytes. INT 1 vector occupies location 4, 5, 6, and 7 and similarly vector for INT 2 occupies locations 8, 9, 10, and 11. As the table is located in RAM it can be changed anytime. Immediately after changing it the interrupt mapping is changed and now the interrupt will result in execution of the new routine. This indirection gives the mechanism extreme flexibility. The operation of interrupt is same whether it is the result of an INT instruction (software interrupt) or it is generated by an external hardware which passes the interrupt number by a different mechanism. The currently executing instruction is completed, the current value of FLAGS is pushed on the stack, then the current code segment is pushed, then the offset of the next instruction is pushed. After this it automatically clears the trap flag and the interrupt flag to disallow further interrupts until the current routine finishes. After this it loads the word at nx4 in IP and the word at nx4+2 in CS if interrupt n was generated. As soon as these values are loaded in CS and IP execution goes to the start of the interrupt handler. When the handler finishes its work it uses the IRET instruction to return to the caller. IRET pops IP, then CS, and then FLAGS. The original value of IF and TF is restored which re-enables further interrupts. IF and TF will be discussed in detail in the discussion of real time interrupts. We have discussed three things till now.

  1. The INT and IRET instruction format and syntax
  2. The formation of IVT (interrupt vector table)
  3. Operation of the processor when an interrupt in generated Just as discussed in the subroutines chapter, the processor will not match interrupt calls to interrupt returns. If a RETF is used in the end of an ISR the processor will still return to the caller but the FLAGS will remain on the stack which will destroy the expectations of the caller with the stack. If we

know what we are doing we may use such different combination of instructions. Generally we will use IRET to return from an interrupt routine. Apart from indirection the software interrupt mechanism is similar to CALL and RET. Indirection is the major difference. The operation of INT can be written as: sp ← sp- [sp] ← flag sp ← sp- if ← 0 tf ← 0 [sp] ← cs sp ← sp- [sp] ← ip