Vous êtes sur la page 1sur 5

InvestigatingIOInterrupts

Introduction
Attheendofthislabyoushouldbeableto:

Describewhatinterruptvectorsareandexplainhowtheyareused
DescribetwomainmethodsofIOinterrupthandling
ExplainthedifferencebetweenthetwomainmethodsofIOinterrupthandling
ComparethemeritsofthetwomainmethodsofIOinterrupthandling

BasicTheory
Computersystemsusetheinterruptmechanismasameansofrespondingto
externaleventssuchasinputandoutputoperations.TheCPUismomentarily
interruptedjustbeforeexecutingthenextinstructionandisforcedtoexecutethe
instructionsofaninterrupthandler.Oncetheinterrupthandlingiscompletedthe
CPUisreturnedbacktoexecutingtheinstructionitwasabouttoexecutebeforeit
wasinterrupted.ThestackisusedtostoretheCPUstatesuchasthecontentsof
registersandthereturnaddresswheninterrupted.Thesearethenrestoredoncethe
interrupthandlerisexited.

LabExercisesInvestigateandExplore
Thelabinvestigationsareaseriesofexercisesthataredesignedtodemonstratethe
variousaspectsofIOinterrupthandling.

Exercise1Describewhatinterruptvectorsareandexplainhowtheyareused
Inthecompilerwindow,checkonlytheboxesGeneratecode,Enableoptimizerand
RedundantCode.Enterthefollowingsourcecodeandcompileit:
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
InthecompiledcodewindowlocatethesubroutinesIntVect1,IntVect2andIntVect5.
Makeanoteofthestartingaddressesofthesesubroutinesbelow:


Subroutine

Startingaddress

IntVect1

IntVect2

IntVect5

Next,dothefollowing:
1. LoadthecodegeneratedinCPUmemory.
2. ClickontheINTERRUPTSbuttontoviewtheINTERRUPTVECTORSwindow.
3. MakeanoteofthenumbersdisplayedintextboxesnexttoINT1,INT2andINT5.
Note:TheINTERRUPTVECTORSwindowinthesimulatorrepresentsthatpartofthe
CPUhardwarethatstoresthevariousinterruptroutineaddresses.

Interrupt

INT1

INT2

INT5

Comparethetwotablesaboveandenterabriefcommentonyourobservationin
thespacebelow:

Now,followtheinstructionsbelow:
1. ClickontheINPUTOUTPUTbuttontoviewtheconsolewindow.
2. SelectStayontopboxesbothintheconsoleandtheinterruptvectorswindows.
3. ResettheVectorsprogramandrunitatthefastestspeed.
4. Whiletheprogramisrunning,clickTRIGGERbuttonsintheinterruptswindow
againstINT1,INT2andINT5oneaftertheother.
5. Observethemessagesdisplayedontheconsole.Commentonyourobservations:

Tip:Ifyouruntheprogramataslowpace(speedsliderdown),youshouldbeableto
seetheeffectsofclickingontheTRIGGERbuttons.

Commentonyourobservationsinthespacebelow:

Exercise2Describetwomainmethodsofinterrupthandling
Enterthefollowingsourcecodeinanewsourceeditorandcompileit.
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:
Thenowaitkeywordinthereadstatementmakessuretheprogramisnot
suspendedwhilewaitingforaninput.
Ifthereisnoinput,thevalueofthevariablevwillremainunchanged.
Thebreak*statementtakestheprogramoutoftheoutermostloopwhichinthis
caseisthewhileloop.
So,now,brieflyexplainwhattheaboveprogramisdoing:

Next,followtheinstructionsbelow:
1. LoadthecodegeneratedinCPUmemory.
2. Setthespeedofsimulationtomaximum.
3. Bringtheconsolewindowup(usetheINPUTOUTPUTbutton).
4. ChecktheStayontopcheckboxontheConsole.
5. ClickintheINPUTboxontheConsole.
6. StartthesimulationbyclickingtheCPUSimulatorsRUNbutton.Assoonasthe
ProgramStartingmessageisdisplayedontheConsole,typeanysinglecharacter
intheINPUTboxoftheConsole.Waituntiltheprogramterminates.

Next,enterthefollowingsourcecodeinanewsourceeditorandcompileit.
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
Brieflyexplainwhattheaboveprogramisdoing(notewherethereadstatementisin
thiscase)

LoadthecodegeneratedinCPUmemory.Resetandrunthiscodeatthefastest
speed.AssoonastheProgramStartingmessageisdisplayedontheConsole,type
anysinglecharacterintheINPUTboxoftheConsole.Waituntiltheprogram
terminates.

Exercise3Explainthedifferencebetweenpolledandvectoredinterrupts
Basedonyourobservationinthepreviousexercise,brieflyexplainthedifferencein
thebehavioursofthetwoprograms,PolledIntandVectoredInt,with
respecttothespeedofresponsetoinput.Explainwhythisdifference.

Basedonyourobservationsinexercises2,andlookingatthetablebelow,which
interrupthandlingmethodlistedinthetable,ismoreefficient(putanXagainstit):
Interruptmethod

Selectthemost
efficientone

Polled
Interrupt

Vectored
Interrupt

Exercise4Comparethemeritsofthetwomainmethodsofinterrupthandling
1. Basedonyourobservationsabove,suggestandbrieflydescribeareason
whereyouwouldusethePolledInterruptmethodinpreferencetothe
VectoredInterruptmethod?

2. VerybrieflydescribewhereyouwouldusetheVectoredInterruptmethod
inpreferencetothePolledInterrupt?

Vous aimerez peut-être aussi