add recursion test, add noops for branch delay slots
This commit is contained in:
parent
16ebc059d9
commit
091c684bf1
12 changed files with 51 additions and 2 deletions
|
@ -23,6 +23,7 @@ _start:
|
||||||
|
|
||||||
# call main
|
# call main
|
||||||
jal main
|
jal main
|
||||||
|
nop
|
||||||
|
|
||||||
# exit
|
# exit
|
||||||
move $a0, $v0
|
move $a0, $v0
|
||||||
|
|
|
@ -11,6 +11,7 @@ result:
|
||||||
move $t0, $a0
|
move $t0, $a0
|
||||||
move $v0, $t0
|
move $v0, $t0
|
||||||
jr $ra
|
jr $ra
|
||||||
|
nop
|
||||||
|
|
||||||
main:
|
main:
|
||||||
# save ra on stack
|
# save ra on stack
|
||||||
|
@ -20,6 +21,7 @@ main:
|
||||||
# set return to 17
|
# set return to 17
|
||||||
li $a0, 17
|
li $a0, 17
|
||||||
jal result
|
jal result
|
||||||
|
nop
|
||||||
|
|
||||||
# pop ra from stack
|
# pop ra from stack
|
||||||
lw $ra, 0($sp)
|
lw $ra, 0($sp)
|
||||||
|
@ -27,3 +29,4 @@ main:
|
||||||
|
|
||||||
# return result
|
# return result
|
||||||
jr $ra
|
jr $ra
|
||||||
|
nop
|
||||||
|
|
|
@ -15,3 +15,4 @@ main:
|
||||||
# return
|
# return
|
||||||
li $v0, 0
|
li $v0, 0
|
||||||
jr $ra
|
jr $ra
|
||||||
|
nop
|
|
@ -24,3 +24,4 @@ main:
|
||||||
# return 1
|
# return 1
|
||||||
li $v0, 0
|
li $v0, 0
|
||||||
jr $ra
|
jr $ra
|
||||||
|
nop
|
||||||
|
|
41
test/masm/recursion.asm
Normal file
41
test/masm/recursion.asm
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Copyright (c) 2024 Freya Murphy
|
||||||
|
|
||||||
|
# file: recursion.asm
|
||||||
|
# test: should recurse sum n..0 numbers
|
||||||
|
|
||||||
|
.text
|
||||||
|
.align 2
|
||||||
|
.globl main
|
||||||
|
|
||||||
|
main:
|
||||||
|
# init $a0
|
||||||
|
li $a0, 5
|
||||||
|
|
||||||
|
sum:
|
||||||
|
# save stack
|
||||||
|
addiu $sp, $sp, -8
|
||||||
|
sw $ra, 0($sp)
|
||||||
|
sw $s0, 4($sp)
|
||||||
|
|
||||||
|
# load n from a0
|
||||||
|
move $s0, $a0
|
||||||
|
|
||||||
|
# skip if n is zero
|
||||||
|
li $v0, 0
|
||||||
|
beq $s0, $zero, add
|
||||||
|
nop
|
||||||
|
jal sum
|
||||||
|
addi $a0, $s0, -1
|
||||||
|
|
||||||
|
add:
|
||||||
|
# n = n + returned
|
||||||
|
add $v0, $s0, $v0
|
||||||
|
|
||||||
|
# restore stack
|
||||||
|
lw $ra, 0($sp)
|
||||||
|
lw $s0, 4($sp)
|
||||||
|
addiu $sp, $sp, 8
|
||||||
|
|
||||||
|
# return
|
||||||
|
jr $ra
|
||||||
|
nop
|
|
@ -13,3 +13,4 @@ main:
|
||||||
# return
|
# return
|
||||||
li $v0, 0
|
li $v0, 0
|
||||||
jr $ra
|
jr $ra
|
||||||
|
nop
|
|
@ -12,4 +12,4 @@ $v1: 0x00000000 $t3: 0x00000000 $s3: 0x00000000 $k1: 0x00000000
|
||||||
$a0: 0x00000000 $t4: 0x00000000 $s4: 0x00000000 $gp: 0x00000000
|
$a0: 0x00000000 $t4: 0x00000000 $s4: 0x00000000 $gp: 0x00000000
|
||||||
$a1: 0x00000000 $t5: 0x00000000 $s5: 0x00000000 $sp: 0x10001000
|
$a1: 0x00000000 $t5: 0x00000000 $s5: 0x00000000 $sp: 0x10001000
|
||||||
$a2: 0x00000000 $t6: 0x00000000 $s6: 0x00000000 $fp: 0x00000000
|
$a2: 0x00000000 $t6: 0x00000000 $s6: 0x00000000 $fp: 0x00000000
|
||||||
$a3: 0x00000000 $t7: 0x00000000 $s7: 0x00000000 $ra: 0x0040001c
|
$a3: 0x00000000 $t7: 0x00000000 $s7: 0x00000000 $ra: 0x00400024
|
0
test/out/recursion
Normal file
0
test/out/recursion
Normal file
1
test/out/recursion.status
Normal file
1
test/out/recursion.status
Normal file
|
@ -0,0 +1 @@
|
||||||
|
15
|
|
@ -12,4 +12,4 @@ $v1: 0x00000000 $t3: 0x00000000 $s3: 0x00000000 $k1: 0x00000000
|
||||||
$a0: 0x00000000 $t4: 0x00000000 $s4: 0x00000000 $gp: 0x00000000
|
$a0: 0x00000000 $t4: 0x00000000 $s4: 0x00000000 $gp: 0x00000000
|
||||||
$a1: 0x00000000 $t5: 0x00000000 $s5: 0x00000000 $sp: 0x10001000
|
$a1: 0x00000000 $t5: 0x00000000 $s5: 0x00000000 $sp: 0x10001000
|
||||||
$a2: 0x00000000 $t6: 0x00000000 $s6: 0x00000000 $fp: 0x00000000
|
$a2: 0x00000000 $t6: 0x00000000 $s6: 0x00000000 $fp: 0x00000000
|
||||||
$a3: 0x00000000 $t7: 0x00000000 $s7: 0x00000000 $ra: 0x00400018
|
$a3: 0x00000000 $t7: 0x00000000 $s7: 0x00000000 $ra: 0x00400020
|
Loading…
Reference in a new issue