MIPS Help: Adding arrays and printing their sum -


add 2 arrays: write mips assembly language program adds 2 arrays (element-by-element addition) , prints sum.

print out element of sum in single line, labeled , values separated spaces. line should terminated \n" character. instance, if arrays , b above, output like: sum is: 1 4 7 6 10 14 11 16 21 16

here's code have far

# data segment  .data     size:    .word  10 #size of first array $a0:    .word  2, 4, 6, 8, 10, 12, 14, 16, 18, 20 #first array's elements size2:   .word 10 #size of second array $a1:   .word -1, 0, 1, -2, 0, 2, -3, 0, 3, -4 #second array's elements size3:   .word 10 #size of third array  main:  la   $t0, $a0   #$t0 points $a0[0]           lw   $t1, size   #$t1 equals number of elements in $a0[]   la   $t2, $a1  #$t2 points $a1[0]  lw   $t3, size2  #$t3 equals number of elements in $a1[]   la $t4, $a0 #load base address of array register $t4 la $t5,  #load base address of array register $t5   assigning array's elements temp variables:  lw $t6,0($a0)  addiu $a0,$a0,4  lw $t7,0($a0)  addiu $a0,$a0,4  lw $t8,0($a0)  addiu $a0,$a0,4  lw $t9,0($a0)  addiu $a0,$a0,4  lw $t10,0($a0)  addiu $a0,$a0,4       # exit program:  li   $v0, 10      # terminate program syscall 

so here's stumped. how go putting every element of both first , second arrays mips values $t0, $t1, etc.

and how go adding them , printing out sum of arrays?

i'm sorry take time have searched hours guide on how add arrays in mips , print sum, no avail

you use a mips instruction set reference check instruction appropriate each step of program.

for example, load 32-bit word $t0 address given in $a0 use lw $t0,0($a0).

to increase $a0 point @ next word use addiu $a0,$a0,4.

to branch label if 2 values (like, say, counter , array length) aren't equal use bne $t2,$a1,some_label.

and on..

by way, i'm not sure $b0 , $b1 supposed be. did mean $t0 , $t1?


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -