Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # int f ( int x ) {
- # if ( x < 2 ) return x + 3;
- # else return f ( x / 3 ) + f ( x - 4 );
- # }
- #
- .data
- par: .word 3
- .text
- main:
- lw $a0,par
- jal f
- j exit
- end_main:
- f:
- add $sp, $sp, -12
- sw $a0, 0($sp)
- sw $ra, 4($sp)
- bge $a0, 2, caso_ricorsivo
- blt $a0, 2, caso_base
- caso_ricorsivo:
- # x / 3
- div $a0, $a0, 3
- mflo $a0
- # f ( x / 3 )
- jal f
- lw $t0, -4($sp)
- # Ripristiniamo il parametro
- lw $a0, 0($sp)
- sub $a0, $a0, 4
- jal f
- lw $t1, -4($sp)
- add $t0, $t0, $t1
- sw $t0, 8($sp)
- lw $ra, 4($sp)
- add $sp, $sp, 12
- jr $ra
- caso_base:
- add $a0, $a0, 3
- sw $a0, 8($sp)
- add $sp, $sp, 12
- jr $ra
- exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement