0

I need to create a Two-Dimensional Array in "row major"order and add up the elements of the row and return the sum in $v0.

I know how to set up the data, i just don't know how to manipulate it to get the sum. And I cannot overflow the registers.

Please help.

Thanks,
Husslela2:cheesy:

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by husslela2
0

I need to create a Two-Dimensional Array in "row major"order and add up the elements of the row and return the sum in $v0.

I know how to set up the data, i just don't know how to manipulate it to get the sum. And I cannot overflow the registers.

Please help.

Thanks,
Husslela2:cheesy:

I'm assuming this is in MIPS, could you post some code.

0

sure....

.data
array: .word 0:12
elements: .word 0,1,2,3,4,5,6,7,8,10,11,12
RowNum: .word 43
ColNum: .word 3
element_size: .word 4
.text
main:
la $a0, array
move $t4, $a0
lw $t1,element_size
lw $t2, RowNum
lw $t3, ColNum
mul $t6, $t3, $t1
lw $t7, elements
rowloop:
lw $t3, ColNum
move $t5, $t4
colLoop:
sw $t7, 0($t5)
add $t5, $t5, $t1
addi $t3, $t3, -1
bgtz $t3, colLoop
add $t4, $t4, $t6
addi $t2, $t2, -1
bgtz $t2, rowloop
ori $v0, $0, 10
syscall

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.