MIPS Procedure Call Interrupt IO Syscall
Transcript of MIPS Procedure Call Interrupt IO Syscall
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
1/37
1
MIPS R2000 Assembly Language(Procedure Call, Interrupt, IO, Syscall)
CS 2 0
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
2/37
2
Procedure Call
!"y do #e need $t% structured programming
reuse frequently used routine !"o ta&es care o' $t%
compiler for HLL programmer for assembly programming
!"at s"ould be done%1. save registers whose values will be needed after the call
who will do this job caller or callee2. save return address!. pass arguments to the callee
Anyt"$ng else% space to store local variables of the callee data structure to handle nested calls
stac"
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
3/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
4/37
&
MIPS Procedure Calls
***
jal loc*
***
***
***
jr $ra*
loc#$ra
caller
callee
+hat if the callee calls another procedure
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
5/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
6/37
Sa $ng Pr$ ate Reg$sters
use reg$sters as many as poss$ble they are much faster than memory (more than 1' times)
there are only a limited number of registers (!2 in /0 ) callee sa e s caller sa e
whichever that needs to save less registers MIPS con ent$ons
$s'..$s3 are callee saves $t'..$t4 are caller saves
problems registers are not enough a procedure calles another procedure solution#
you save5restore variables on the stac" carefully stac& 'rame $t $s 'or a comp$ler
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
7/37
3
Stac& *rame
purpose store data used by a procedure in a single frame
data can be accessed using a single pointer ($fp) within a procedure the stac" may be used for other purpose e6pression evaluation
accessing data using $sp can be tric"y stac" is used for other purposes Is $t really necessary%
yes% for recursive calls yes% for comple6 chained procedure calls no% for simple programs compilers use it 7
contents $n a stac& 'rame arguments other than stored in a'..a! saved register values variables local to the procedure
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
8/37
8
Stac& *rame
stack
old $fpargument 5
argument 6
savedregisters
localvariables
$spstack growsand shrinks
duringexpressionevaluation
.
9 of procedue :
9 of procedue ;
9 of procedue eroes
8a8 not a number >ero5>ero
exponent fraction
( ? $53normali1ed
fraction
% denormali1edfraction
$55 %
% %
$55 non21ero
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
21/37
21
MIPS *loat$ng Po$nt Reg$sters
FGR 0
Floating PointGeneral Purpose Registers
(FGR)
FGR 1
FGR
FGR !
FGR "
FGR #
FGR $
FGR %FGR !0
FGR !1
Floating PointRegisters (FPR)
least
mostFPR 0
least
mostFPR
least
mostFPR !0
least
mostFPR $
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
22/37
22
MIPS *P Instruct$ons
&P 'escription
l.d !f3" addr s.s !f3" addr mov.d !f3" !f6
ctc( !@" rdcfc( !6" rd
cvt.s.fmtcvt.d.fmtcvt.w.fmt
load d2word to !f3store s2word from !f3move word
move control word to PAmove from
convert to single Pconvert to double Pconvert to fixed point
fmt Formats single precisiond double precisionw binar fixed point &integer'
e6maple# cvt.s.w 9Edest% 9Esrccvt.d.w 9Edest% 9Esrccvt.d.s 9Edest% 9Esrc
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
23/37
2!
MIPS *P Instruct$ons (2)
&P 'escription
add.fmtsub.fmtmul.fmtdiv.fmtabs.fmt
mov.fmtneg.fmt
addsubstractmultipldivideabsolute value
move fp to fpnegate
compare and branch
c.cond.format (" $bc(t labelbc(f label
cond ConditioneD" le" lt" t" f" or" nlt" gt" ..result sets a flag in PAbranch instruction on this flag
BC(, label 0 branch if trueBC( label 0 branch if false
e6maple# add.s 9rdest% 9Esrc1% 9Esrc2 add.d 9rdest% 9Esrc1% 9Esrc2 sub.s 9rdest% 9Esrc1% FEsrc2
e6maple# c.eq.s 9Esrc1% 9Esrc2 bc1t 666
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
24/37
2&
./cept$on
./cept$on > unprogrammed control trans'er
system ta"es action to handle the e6ception must record the address of the offending instruction
returns control to user must save - restore user state
user program
normal control flow seDuential" )umps" branches" calls" returns
E stemFxceptionGandler Fxception
return from
exception
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
25/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
26/37
2
#o ypes o' ./cept$ons
Interrupts caused by e6ternal events
asynchronous to program e6ecution may be handled between instructions simply suspend and resume user program
raps caused by internal events
e6ceptional conditions (overflow) errors (parity) faults (non?resident page)
synchronous to program e6ecution condition must be remedied by the handler instruction may be retried or simulated and program continued or program may
be aborted
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
27/37
23
MIPS Con ent$on
e6ception means any une6pected change in control flow% without distinguishinginternal or e6ternal
use the term interrupt only when the event is e6ternally caused.
Type of event From where? MIPS terminology
05G device request C6ternal 0nterrupt0nvo"e G from user program 0nternal C6ception:rithmetic overflow 0nternal C6ception
Ising an undefined instruction 0nternal C6ceptionHardware malfunctions Cither C6ception or 0nterrupt
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
28/37
28
Address$ng t"e ./cept$on andler
rad$t$onal Approac"4 Interupt Bector < J? /C/K 0 Mbase D cause NN ''O
!3'% 8'''% a6% 8'68 % . . .
MIPS Approac"4 '$/ed entry < J? CP
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
29/37
24
Sa $ng State
Pus" $t onto t"e stac& a6% 8"% 8'68
Sa e $t $n spec$al reg$sters /0 C
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
30/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
31/37
!1
Cause Reg$ster
Pend$ng $nterrupt 6 "ard#are le els4 b$t set $' $nterrupt occurs but not yet ser $ced handles cases when more than one interrupt occurs at same time% or while records
interrupt requests when interrupts disabled ./cept$on Code encodes reasons 'or $nterrupt
' (0RQ) BS e6ternal interrupt 1=! BS QL; related & (:FFEL) BS address error e6ception (load or instr fetch) , (:FFE ) BS address error e6ception (store) (0;I ) BS bus error on instruction fetch 3 (F;I ) BS bus error on data fetch
8 ( yscall) BS yscall e6ception 4 (;T Q) BS ;rea"point e6ception 1' (E0) BS Eeserved 0nstruction e6ception 12 (G 9) BS :rithmetic overflow e6ception
Status:6 :0
Pend$ng
6 2
Code
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
32/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
33/37
!!
Input and Output
IO
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
34/37
!&
SPIM IO
memory mapped IO & registers are mapped to memory locations
to read data 'rom &eyboard Eeady bit means that the UEeceived dataV register has a data. +hen a data arrives% interrupt is raised if it is enabled .
(
9nterruptenable
ead
(Inused
eceiver control&%xffff%%%%'
4
eceived b te
Inused
eceiver data&%xffff%%%3'
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
35/37
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
36/37
SPIM ll
-
8/10/2019 MIPS Procedure Call Interrupt IO Syscall
37/37
!3
SPIM syscall mo e a04 tli 04 1
s3scall
ser $ce call code arguments results print integer 1 int in $a'
print float 2 float in $a' print double ! double in $a' print string & addr of string in $a'
read integer , int in $v'read float float in $v'read double 3 double in $v'read string 8 $a'Bbuffer% $a1Blength
sbr" 4 $a' B amount addr in $v'e6it 1'