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 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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.