# This version uses the .data and .text directives to # distinguish the section that has data from the one # having instructions, for the benefit of the assembler. # It also has the entry point symbol (__start) defined, # and uses the .global directive to make sure that symbol is # "exported" (so that the linker will see it). .data N: .word 5 # reserve and initialize a word result: .space 4 # reserve but don't initalize a word .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 halt # all done