Created
October 29, 2014 00:39
-
-
Save eaddingtonwhite/8a0f32bf7f23cdfa0b5b to your computer and use it in GitHub Desktop.
Sums an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
L1: .word 2,4,6,8,10,12,14,16 # the array | |
.text | |
.globl main | |
main: add $t0, $0, $0 # initialize $t0=0 | |
add $t1, $0, $0 # initialize the sum = 0 | |
lw $t2, L1($t0) # load first value | |
add $t1, $t1, $t2 # add to sum | |
addi $t0, $t0, 8 # computer addr of two elements down | |
lw $t2, L1($t0) # load second value | |
add $t1, $t1, $t2 # add to sum | |
addi $t0, $t0, 8 # computer addr of two elements down | |
lw $t2, L1($t0) # load third value | |
add $t1, $t1, $t2 # add to sum | |
addi $t0, $t0, 8 # computer addr of two elements down | |
lw $t2, L1($t0) # load fourth value | |
add $t1, $t1, $t2 # add to sum | |
li $v0, 10 | |
syscall #end the program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment