MIPS 中的二维数组 [英] 2D Array in MIPS
问题描述
我在网上和这个网站上搜索过,我找不到在 MIPS 中实现二维数组的好例子.我希望能够看到一个示例,说明如何遍历数组以将数据放置在特定索引处以及如何打印出如下所示的数组.
I've searched online and on this site and I can not find a good example of implementing a 2D Array in MIPS. I would like to be able to see an example of how to go through the array in order to place data at a specific index and how to print the array out like shown below.
例如一个 5x5 数组,其中 $ 将是每个索引中的数据.
Such as a 5x5 array where $ would be the data in each index.
a b c d e
1 $ $ $ $ $
2 $ $ $ $ $
3 $ $ $ $ $
4 $ $ $ $ $
5 $ $ $ $ $
推荐答案
您可以根据一维数组来设置二维数组.您只需要正确地将元素从一维数组映射到二维数组.本站有图片:
You can set up a 2D array in terms of a 1D array. You just need to correctly map elements from the 1D array to the 2D array. This site has pictures:
http://www.种植园生产.com/Webster/www.artofasm.com/Windows/HTML/Arraysa2.html#1010609
您可以使用标准格式来寻址每个单元格.例如:
You can use a standard format for addressing each cell. For example:
a b c d e
1 0 1 2 3 4
2 5 6 7 8 9
3 10 11 12 13 14
4 15 16 17 18 19
5 20 21 22 23 24
您应该能够看到模式:) 一般来说,如果有 M 列和 N 行,则可以在点 i * M + j - 1 处访问第 i 行第 j 列(零索引)的单元格
You should be able to see the pattern :) In general, if there are M columns and N rows, the cell at row i, column j (zero-indexed) can be accessed at point i * M + j - 1
这篇关于MIPS 中的二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!