Add Two Arrays Write a MIPS assembly language program that a

Add Two Arrays:

Write a MIPS assembly language program that adds two arrays with ten elements ( element - by - element addition) and save them in an array. Print the sum.

Solution

main:

la $a0,prompt1

li $v0,4

syscall

li $s0,0

la $s1,x

li $v0,5

syscall

mul $t0,$s0,4

add $t0,$s1,$t0

sw $v0,($t0)

add $s0,$s0,1

blt $s0,5,rd_loop

li $s0,0

la $s1,y

la $a0,prompt2

li $v0,4

syscall

rd_loop1:

li $v0,5

syscall

mul $t0,$s0,4

add $t0,$s1,$t0

sw $v0,($t0)

add $s0,$s0,1

blt $s0,5,rd_loop1

li $s0,0

la $s1,x

la $s2,y

la $s3,sum

loop:

mul $t3,$s0,4

add $t0,$s1,$t3

add $t1,$s2,$t3

add $t2,$s3,$t3

lw $t4,($t0)

lw $t5,($t1)

add $t4,$t5,$t4

sw $t4,($t2)

add $s0,$s0,1

blt $s0,5,loop

li $s0,0

la $a0,newline

li $v0,4 syscall

la $t0,sum

wr_loop:

move $a0,$s0

li $v0,1

syscall

la $a0,spaces

li $v0,4

syscall

mul $t1,$s0,4

add $t1,$t1,$t0

lw $a0,($t1)

li $v0,1

syscall

la $a0,newline

li $v0,4

syscall

add $s0,$s0,1

blt $s0,5,wr_loop

li $v0,10

syscall

Add Two Arrays: Write a MIPS assembly language program that adds two arrays with ten elements ( element - by - element addition) and save them in an array. Prin
Add Two Arrays: Write a MIPS assembly language program that adds two arrays with ten elements ( element - by - element addition) and save them in an array. Prin
Add Two Arrays: Write a MIPS assembly language program that adds two arrays with ten elements ( element - by - element addition) and save them in an array. Prin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site