Java Reference
In-Depth Information
subi
$sp,$sp,20
# Push frame on stack
sw
$ra,0($sp)
# Save return address
sw
$fp,4($sp)
# Save old frame pointer
move
$fp,$sp
# Set $fp to access new frame
sw
$a0,8($fp)
# Store limit in frame
sw
$0,12($fp)
# Store 0 ($0) into sum
li
$t0,1
# Load 1 into $t0
sw
$t0,16($fp)
# Store 1 into i
j
L2
# Go to end of loop test
L1:
lw
$t1,12($fp)
# Load sum into $t1
lw
$t2,16($fp)
# Load i into $t2
add
$t3,$t1,$t2
# Add sum + i into $t3
sw
$t3,12($fp)
# Store sum + i into sum
lw
$t4,16($fp)
# Load i into $t2
addi
$t4,$t4,1
# Increment $t4 by 1
sw
$t4,16($fp)
# Store $t4 into i
L2:
lw
$t5,16($fp)
# Load i into $t5
lw
$t6,8($fp)
# Load limit into $t6
sle
$t7,$t5,$t6
# set $t7 = i <= limit
bnez
$t7,L1
# Goto L1 if i <= limit
lw
$t8,12($fp)
# Load sum into $t8
move
$a0,$t8
# Copy $t8 to parm register
jal
String_toString_int_ # Call toString
# String ref now is in $v0
lw
$ra,0($fp)
# Reload return address
lw
$fp,4($fp)
# Reload old frame pointer
addi
$sp,$sp,20
# Pop frame from stack
jr
$ra
# Jump to return address
Figure 13.8: MIPS code for method stringSum
Search WWH ::




Custom Search