# This version does output, using direct calls to operating # system services (the syscall instructions). .data # begin data section N: .word 5 # reserve and initialize a word result: .space 4 # reserve but don't initalize a word msg: .asciiz "The factorial is: " newline: .asciiz "\n" .text # begin program text .global __start __start: addi $t0, $0, 1 # $t0 will hold result, initially 1 lw $t1, N($gp) # $t1 will hold N, initially 9 top: beq $t1, $0, bottom mult $t0, $t0, $t1 # result = result * N addi $t1, $t1, -1 # decrement N j top # goto top bottom: sw $t0, result($gp) # we'd better save result addi $v0, $0, 4 # finished w/ loop, now print out addi $a0, $gp, msg # message, by invoking syscall 4 syscall # (print_string) addi $v0, $0, 1 # now print out result, by lw $a0, result($gp) # invoking syscall 1 (print_int) syscall addi $v0, $0, 4 # print a newline (w/ syscall 4) addi $a0, $gp, newline syscall halt