Download presentation

Presentation is loading. Please wait.

Published byKiara Ferrer Modified about 1 year ago

4
.text fact: addiu $sp, $sp, -32 sw $ra, 20($sp) sw $fp, 16($sp) addiu $fp, $sp, 28 sw $a0, 0($fp) bgtz $a0, L2 li $v0, 1 b suffix L2: addi $a0, $a0, -1 # or addiu ? jal fact # fact(n-1) now in $v0 lw $t0, 0($fp) # pick up n mul $v0, $v0, $t0 suffix: # note: return value must be already set in $v0 lw $fp, 16($sp) lw $ra, 20($sp) addiu $sp, $sp, 32 jr $ra

5
main: addiu $sp, $sp, -4 # minimum prolog sw $ra, 0($sp) # print a prompt li $v0, 4 la $a0, prompt syscall # read a number li $v0, 5 syscall move $a0, $v0 # compute its factorial jal fact # print the factorial move $a0, $v0 li $v0, 1 syscall lw $ra, 0($sp) # minimum epilog addiu $sp, $sp, 4 jr $ra.data prompt:.asciiz "Enter a small number\n" outputLabel:.asciiz "The factorial is " newline:.asciiz "\n"

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google