# Dit programma berekent fac(x) voor x=1,...,6, en plaatst de resultaten # in mem[200],...,mem[212]. fac(x) = 1.2. ... .x, fac(3)=1.2.3=6. main: addi $7,$0,1 # fac(1) = 1 addi $5,$0,200 # init base data adress sh $7,0($5) # init fac(1) in mem nop addi $4,$0,2 # init x=2 loop: lh $7,0($5) # fac(x-1) nop add $2,$0,$0 # clear add $3,$0,$0 # init mult teller op 0 IL: add $2,$2,$7 # fac(x) := fac(x) + fac(x-1) addi $3,$3,1 # mult := mult + 1 slt $10,$3,$4 # if mult=x then fac(x) is bne $0,$10, IL # calculated nop sh $2,2($5) # store fac(x) in mem addi $4,$4,1 # inc(x) addi $5,$5,2 slti $10,$5,212 bne $0,$10, loop # if not yet all fac(.) calculated nop # then loop break 0