A Sample MIPS program

-------------------------------------------------------------- .data prompt: .asciiz "\n Please input a value for N = " result: .asciiz "The sum of the integers 1 to N = " bye: .asciiz "\n Good-bye!" .globl main .text main: li $v0, 4 # System call code for Print String la $a0, prompt # load address of prompt into $a0 syscall # Print the prompt message li $v0, 5 # System call code for Read Integer syscall # Read N into $v0 blez $v0, end # branch to end if v0 <= 0 li $t0, 0 loop: add $t0, $t0, $v0 # Sum of integers in $t0 addi $v0, $v0, -1 # Decrement N bnez $v0, loop # branch to loop if v !=0 li $v0, 4 # System call code for Print String la $a0, result # load adress of message into $a0 syscall # print the string li $v0, 1 # System calll code for Print Integer move $a0, $t0 # move value to be printed to $a0 syscall # print sum of integers b main # branch to main end: li $v0, 4 # System call code for Print String la $a0, bye # load address of message into $a0 syscall # print the string li $v0, 10 # System call code for terminate syscall # return control to system