简体   繁体   中英

How to implement 2D array in MIPS

The information that i have found on the internet for this is not explained very well. I would like to know how to go about implementing a 2-D array of double-precision floating point numbers. I would like the dimensions of the array to be variable so if I say .double 100, then I am wasting a lot of memory because that may not be the size of the array eg could be 5 x 5. Would I have to use the stack to solve this problem? Or how else could I go about it? Also if someone could explain how to efficiently fill the array it would be much appreciated!

You can implement any rectangular 2D array as 1D array using row-major order , the only different would be is in calculating the address of the element.

For example if you have a 3×5 array of double 's and you want to access the element array[x][y] , you can calculate its address using the formula:

address of array[x][y] = base of array + 8 * (5 * x + y)

where base of array is the base address of array or array[0][0] , 8 is the size of an element sizeof(double) and 5 is the number of columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM