Array size known only at runtime in MIPS

2019-05-01 16:50发布

问题:

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

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

回答1:

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

So your steps would be:

  • Get the array size from the user
  • Square it
  • Make syscall 9 with the size you calculated