# MIPS example: Manipulating arrays # Function: This code adds the corresponding element of two vectors V1 and V2 and # puts the result of the sum in the corresponding positions of a vector V3 # .text # Add what follows to the text segment of the program .globl main # Declare the label main to be a global one main: la $t0,V1 la $t1,V2 la $t2,V3 la $t3,size # get address of size lw $t3,0($t3) # register $t1 contains the size of the array loop: blez $t3,end # if size is/becomes 0, end of processing lw $t4,0($t0) lw $t5,0($t1) addu $t4,$t4,$t5 sw $t4,0($t2) # update array addiu $t0,$t0,4 addiu $t1,$t1,4 addiu $t2,$t2,4 addiu $t3,$t3,-1 j loop # continue execution # The program is finished. Exit. li $v0,10 # system call for exit end: syscall # Exit! .data V1: .word 0x12 0xff 0x3 0x14 0x878 0x31 0x62 0x10 0x5 0x16 0x20 V2: .word 0x12 0xff 0x3 0x14 0x878 0x31 0x62 0x10 0x5 0x16 0x20 V3: .word 0x0 0x0 0x0 0X0 0x0 0x0 0x0 0X0 0x0 0x0 0x0 size: .word 11