# CSSE 232 - Winter 2003-2004 # Program to test assembler .text # Text section of the program (as opposed to data). .globl main main: li $s0, 0x100 # N move $a0, $s0 jal Sum # Call procedure to determine Sum move $s1, $v0 li $v0, 10 # If you don't have equivalent statements to exit, that's # fine syscall Sum: # Procedure determines the sum from 1 to N; Stores the same in memory # Returns the same to the calling procedure move $t0, $a0 # N li $t1, 0 # i = 0 li $t2, 0 # sum = 0 Add: addi $t1, $t1, 1 # i = i + 1 add $t2, $t2, $t1 # sum = sum + i bne $t0, $t1, Add # if(i == N) then done la $t4, total # Store the sum in memory sw $t2, 0($t4) move $v0, $t2 jr $ra .data total : .word 0