数组大小仅在运行时在MIPS中已知

时间:2022-06-01 21:40:34

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...

所以我有一个棋盘游戏,用户需要输入3,4,5的大小...将是3x3,4x4,5x5等...

Here:

board: .word 0:100  # declare a board of size 100 and make ints '0' , O = 1, X = 2

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...

正如你所看到的,这是静态声明...我需要以某种方式使数组成为在t0中找到的用户输入的SIZE,例如......

1 个解决方案

#1


8  

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

听起来你需要在堆上分配一些内存。 MARS模拟器系统调用是$ v0 = 9,$ a0 =要分配的字节数,返回$ v0中分配的内存的地址。资料来源:MARS提供的MIPS系统调用功能

So your steps would be:

所以你的步骤将是:

  • Get the array size from the user
  • 从用户获取数组大小

  • Square it
  • Make syscall 9 with the size you calculated
  • 使用您计算的大小制作系统调用9

#1


8  

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

听起来你需要在堆上分配一些内存。 MARS模拟器系统调用是$ v0 = 9,$ a0 =要分配的字节数,返回$ v0中分配的内存的地址。资料来源:MARS提供的MIPS系统调用功能

So your steps would be:

所以你的步骤将是:

  • Get the array size from the user
  • 从用户获取数组大小

  • Square it
  • Make syscall 9 with the size you calculated
  • 使用您计算的大小制作系统调用9