数组大小仅在MIPS的运行时已知 [英] Array size known only at runtime in MIPS
问题描述
所以我有一个棋盘游戏,希望用户输入棋盘的大小 3,4,5 ...将是3x3、4x4、5x5等...
So I have a board game and the user is expected to enter the size of the board 3,4,5 ...will be 3x3, 4x4, 5x5, etc...
这里:
board: .word 0:100 # declare a board of size 100 and make ints '0' , O = 1, X = 2
如您所见,这是静态声明...例如,我需要以某种方式使数组成为t0中找到的用户输入的大小...
As you can see, this is static declaration...I need to somehow make an array the SIZE of the user input found in t0 for example...
推荐答案
听起来您需要在堆上分配一些内存.为此,MARS仿真器syscall
为$ v0 = 9,$ a0 =要分配的字节数,返回$ v0中已分配内存的地址.来源: MARS中可用的MIPS syscall函数
It sounds like you need to allocate some memory on the heap. The MARS emulator syscall
for that is $v0 = 9, $a0 = number of bytes to allocate, returns address of allocated memory in $v0. Source: MIPS syscall functions available in MARS
所以您的步骤将是:
- 从用户那里获取数组大小
- 平方它
- 使用您计算出的大小进行syscall 9
这篇关于数组大小仅在MIPS的运行时已知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!