Documente Academic
Documente Profesional
Documente Cultură
In a two-pass assembler
PASS 1: Symbol table generation
.data
Res: .space 4
.text
.globl main
syscall
First, a symbol table is formed. It starts
registers.
For some machines, YES, but not in MIPS! What are the
Load-store architecture.
Push x x x x x * (y+z)
Push y y y+z
Push z z
Add
Multiply
Pop f
Computer Arithmetic: Dealing with overflow
+14 = 0, 1 1 1 0
-14 = 1, 0 0 1 0
+12 = 0, 1 1 0 0 +12 = 0, 1 1 0 0
+2 = 0, 0 0 1 0 +7 = 0, 0 1 1 1
add add
+14 = 0, 1 1 1 0 ? = 1, 0 0 1 1 (WRONG)
0 0 0 1
+12 = 0, 1 1 0 0 +12 = 0, 1 1 0 0
+2 = 0, 0 0 1 0 +7 = 0, 0 1 1 1
add add
+14 = 0, 1 1 1 0 ? = 1, 0 0 1 1 (WRONG)
The following sequence of MIPS instructions can detect
no_overflow:
...
...
overflow:
mouse click
timeout
disk error
divide-by-0
keyboard needs attention
P
overflow
security
violation printer out of paper
Examples:
Examples:
o Arithmetic overflow
o System call
User Kernel
Mode Mode
Also called
Supervisor
Mode
CAUSE REGISTER
Interrupt Mask
15-8 1 0
Kernel/Use
r
(you dont have the luxury to plan ahead and use a JAL
Next instruction
Overflow
ra EPC; jr ra
Invalid instruction
ra EPC; jr ra
System Call
ra EPC; jr ra
main
interrupt / exception
Exceptions cause mostly unscheduled procedure calls.
Example
1:
Read
one
input
from
a
Keyboard
Consider
reading
a
value
from
the
keyboard.
Assume
that
the
interrupt
enable
bit
is
set
to
1.
The
first
line,
".text
0x80000080"
places
the
code
explicitly
at
the
memory
location
where
the
interrupt
service
routine
is
called.
.text
0x80000080
mfc0
$k0,
$13
#
$k0
=
$Cause;
mfc0
$k1,
$14
#
$k1
=
$EPC;
andi
$k0,
$k0,
0x003c
#
$k0
&=
0x003c
(hex);
#
Filter
the
Exception
Code;
bne
$k0,
$zero,
NotIO
#
if
($k0
0)
go
to
NotIO
#
Exception
Code
0
=>
I/O
instr.
sw
$ra,
save0($0)
#
save0
=
$ra;
jal
ReadByte
#
ReadByte();
(Get
the
byte).
lw
$ra,
save0($0)
#
$ra
=
save0;
jr
$k1
#
return;
NotIO:
Other
routines
here
.text main:
teqi $t0,0 # trap when $t0 contains 0
li $v0, 10 # After return syscall
# terminate normally
.ktext 0x80000180
.kdata
msg: .asciiz "Trap generated"