954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Two-Dimensional Arrays

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:

husslela2
Newbie Poster
3 posts since Mar 2007
Reputation Points: 10
Solved Threads: 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.

MacGyver Orca
Light Poster
39 posts since Jan 2007
Reputation Points: 19
Solved Threads: 4
 

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

husslela2
Newbie Poster
3 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You