I need help creating a two dimensional array in mips assembly. I am new to this kind of programming and i do not know how to approach the problem.
i have to create an array max size 20 by 20 and then fill it up with data entered by the keyboard.

5 Years
Discussion Span
Last Post by Ancient Dragon

Create it exactly like you would a 1d array but twice as large. If its an integer array then it needs to be sizeof(int) * 20 * 20 bytes, or 4*20*20 = 1600 bytes.How you store the data is pretty much up to you. One way is to store all 20 integers of the first array first, followed by all 20 of the second array. So, the first integer of the first dimension would be stored at offset 0, while the first integer of the second dimension would be stored at offset 20*4 = 80 byte offset.

If you use a loop counter for data entry of all 400 integers, you can calculate the offset like this (assumes 32-bit integers):

int i = row number (0-19)
int c = column number (0-1)
int offset = (i * 20 * 4) + (c * 4)

Now just convert the above to assembly. let eax = i, ecx = c, and edx offset. I don't know mips asssembly, but just substitute those three registers in intel processors for whatever registers you have in mips.

Edited by Ancient Dragon: n/a


would this change if i want to store floating point values?


The only difference would be to change the 4 (which is the size of a 32-bit integer) to the size of a float, whatever that is.

This question has already been answered. 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.