Laboratory Exercise 7
Laboratory Exercise 7
OBJECTIVES
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
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
In the compiled code window locate the subroutines IntVect1, IntVect2 and IntVect5.
Make a note of the starting addresses of these subroutines below:
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:
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.
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.
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.
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)
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
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.
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/