0% found this document useful (0 votes)
435 views

Laboratory Exercise 7

This document describes a laboratory exercise on investigating IO interrupts. The objectives are to describe interrupt vectors, the two main methods of IO interrupt handling, and compare their merits. The methodology section explains how interrupts work at a basic level. The activities section includes exercises to have the student describe interrupt vectors, demonstrate polled and vectored interrupt handling methods, explain the difference between them, and compare their efficiency and appropriate uses.

Uploaded by

Angelo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
435 views

Laboratory Exercise 7

This document describes a laboratory exercise on investigating IO interrupts. The objectives are to describe interrupt vectors, the two main methods of IO interrupt handling, and compare their merits. The methodology section explains how interrupts work at a basic level. The activities section includes exercises to have the student describe interrupt vectors, demonstrate polled and vectored interrupt handling methods, explain the difference between them, and compare their efficiency and appropriate uses.

Uploaded by

Angelo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LABORATORY EXERCISE #7: Investigating IO Interrupts

OBJECTIVES

At the end of this laboratory exercise, you should be able to:

 Describe what interrupt vectors are and explain how they are used
 Describe two main methods of IO interrupt handling
 Explain the difference between the two main methods of IO interrupt handling
 Compare the merits of the two main methods of IO interrupt handling

I. MATERIALS NEEDED
DESCRIPTION QUANTITY
Laptop 1
CPU-OS Simulator 1

II. METHODOLOGY

Computer systems use the interrupt mechanism as a means of responding to


external events such as input and output operations. The CPU is momentarily
interrupted just before executing the next instruction and is forced to execute
the instructions of an interrupt handler. Once the interrupt handling is complet
ed the CPU is returned back to executing the instruction it was about to execu
te before it was interrupted. The stack is used to store the CPU state such as
the contents of registers and the return address when interrupted. These are
then restored once the interrupt handler is exited.

III. ACTIVITIES

Exercise 1 – Describe what interrupt vectors are and explain how they are used
In the compiler window, check only the boxes Generate code, Enable optimizer and
Redundant Code. Enter the following source code and compile it:
program Vectors
sub IntVect1 intr 1
writeln("This is intr 1")
end sub

sub IntVect2 intr 2


writeln("This is intr 2")
end sub

sub IntVect5 intr 5


writeln("This is intr 5")
end sub
while true
wend end

In the compiled code window locate the subroutines IntVect1, IntVect2 and IntVect5.
Make a note of the starting addresses of these subroutines below:

Subroutine Starting address

IntVect1

IntVect2

IntVect5
Next, do the following:
1. Load the code generated in CPU memory.
2. Click on the INTERRUPTS… button to view the INTERRUPT VECTORS window.
3. Make a note of the numbers displayed in text boxes next to INT1, INT2 and INT5.
Note: The INTERRUPT VECTORS window in the simulator represents that part of the
CPU hardware that stores the various interrupt routine addresses.

Interrupt

INT1

INT2

INT5

Compare the two tables above and enter a brief comment on your observation in the
space below:

Now, follow the instructions below:


1. Click on the INPUT OUTPUT… button to view the console window.
2. Select Stay on top boxes both in the console and the interrupt vectors windows.
3. Reset the Vectors program and run it at the fastest speed.
4. While the program is running, click TRIGGER buttons in the interrupts window
against INT1, INT2 and INT5 one after the other.
5. Observe the messages displayed on the console. Comment on your observations:

Tip: If you run the program at a slow pace (speed slider down), you should be able to
see the effects of clicking on the TRIGGER buttons.
Comment on your observations in the space below:
Exercise 2 – Describe two main methods of interrupt handling
Enter the following source code in a new source editor and compile it. program
PolledInt
var v integer

v = 0
writeln("Program Starting")
while true
read(nowait, v)
for i = 1 to 100
if v > 0 then
break *

end if
write(".")
next
wend
writeln("Program Ending")
end

Notes:
 The nowait keyword in the read statement makes sure the program is not
suspended while waiting for an input.
 If there is no input, the value of the variable v will remain unchanged.
 The break * statement takes the program out of the outermost loop which in
this case is the while loop.

So, now, briefly explain what the above program is doing:

Next, follow the instructions below:


1. Load the code generated in CPU memory.
2. Set the speed of simulation to maximum.
3. Bring the console window up (use the INPUT OUTPUT… button).
4. Check the Stay on top check box on the Console.
5. Click in the INPUT box on the Console.
6. Start the simulation by clicking the CPU Simulator’s RUN button. As soon as the
Program Starting message is displayed on the Console, type any single character in
the INPUT box of the Console. Wait until the program terminates.
Next, enter the following source code in a new source editor and compile it.
program VectoredInt
var v integer

sub InputInt intr 1


read(nowait, v)
end sub

v = 0
writeln("Program Starting")
while true
for i = 1 to 100
if v > 0 then
break *

end if
write(".")
next
wend
writeln("Program Ending")
end

Briefly explain what the above program is doing (note where the read statement is in
this case)

Load the code generated in CPU memory. Reset and run this code at the fastest speed.
As soon as the Program Starting message is displayed on the Console, type any single
character in the INPUT box of the Console. Wait until the program terminates.

Exercise 3 – Explain the difference between polled and vectored interrupts


Based on your observation in the previous exercise, briefly explain the difference in the
behaviours of the two programs, PolledInt and VectoredInt, with respect to
the speed of response to input. Explain why this difference.
Based on your observations in exercises 2, and looking at the table below, which
interrupt handling method listed in the table, is more efficient (put an X against it):
Interrupt method Select the most
efficient one

Polled
Interrupt

Vectored
Interrupt

Exercise 4 – Compare the merits of the two main methods of interrupt handling
1. Based on your observations above, suggest and briefly describe a reason where
you would use the Polled Interrupt method in preference to the Vectored
Interrupt method?

2. Very briefly describe where you would use the Vectored Interrupt method in
preference to the Polled Interrupt?
Appendix ‐ Simulator Instruction Sub‐set
Instruction Description
Data transfer instructions
MOV Move data to register; move register to register
e.g.
MOV #2, R01 moves number 2 into register R01
MOV R01, R03 moves contents of register R01 into register R03
LDB Load a byte from memory to register
e.g.
LDB 1022, R03 loads a byte from memory address 1022 into R03
LDB @R02, R05 loads a byte from memory the address of which is in R02
LDW Load a word (2 bytes) from memory to register
Same as in LDB but a word (i.e. 2 bytes) is loaded into a register
STB Store a byte from register to memory
STB R07, 2146 stores a byte from R07 into memory address 2146
STB R04, @R08 stores a byte from R04 into memory address of which is in
R08
STW Store a word (2 bytes) from register to memory
Same as in STB but a word (i.e. 2 bytes) is loaded stored in memory
PSH Push data to top of hardware stack (TOS); push register to TOS
e.g.
PSH #6 pushes number 6 on top of the stack
PSH R03 pushes the contents of register R03 on top of the stack
POP Pop data from top of hardware stack to register
e.g.
POP R05 pops contents of top of stack into register R05
Note: If you try to POP from an empty stack you will get the error message
“Stack underflow”.

Arithmetic instructions
ADD Add number to register; add register to register
e.g.
ADD #3, R02 adds number 3 to contents of register R02 and stores the
result in register R02.
ADD R00, R01 adds contents of register R00 to contents of register R01
and stores the result in register R01.

SUB Subtract number from register; subtract register from register

MUL Multiply number with register; multiply register with register

DIV Divide number with register; divide register with register

Control transfer instructions


JMP Jump to instruction address unconditionally
e.g.
JMP 100 unconditionally jumps to address location 100 where there is
another instruction
JLT Jump to instruction address if less than (after last comparison)

JGT Jump to instruction address if greater than (after last comparison)

JEQ Jump to instruction address if equal (after last comparison instruction) e.g.
JEQ 200 jumps to address location 200 if the previous comparison
instruction result indicates that the two numbers are equal, i.e. the Z status
flag is set (the Z box will be checked in this case).
JNE Jump to instruction address if not equal (after last comparison)

MSF Mark Stack Frame instruction is used in conjunction with the


CAL instruction. e.g.
MSF reserve a space for the return address on program stack CAL
1456 save the return address in the reserved space and jump to
subroutine in address location 1456

CAL Jump to subroutine address (saves the return address on program stack)
This instruction is used in conjunction with the MSF instruction. You’ll need
an MSF instruction before the CAL instruction. See the example above

RET Return from subroutine (uses the return address on stack)

SWI Software interrupt (used to request OS help)

HLT Halt simulation

Comparison instruction
CMP Compare number with register; compare register with register
e.g.
CMP #5, R02 compare number 5 with the contents of register R02
CMP R01, R03 compare the contents of registers R01 and R03
Note:
If R01 = R03 then the status flag Z will be set, i.e. the Z box is checked. If
R03 > R01 then non of the status flags will be set, i.e. none of the status
flag boxes are checked.
If R01 > R03 then the status flag N will be set, i.e. the N status box is
checked.

Input, output instructions


IN Get input data (if available) from an external IO device

OUT Output data to an external IO device


e.g.
OUT 16, 0 outputs contents of data in location 16 to the console (the
second parameter must always be a 0)

Source:
 http://en.freedownloadmanager.org/Windows-PC/CPU-OS-Simulator-
FREE.html
 http://www.teach-sim.com/
 http://softdeluxe.com/CPU-OS-Simulator-1264697/download/

You might also like