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...
So deciding an array size at runtime is possible in modern C (>= C99) and code like the below is fine: int s; printf("Enter the array size: "); scanf("%d", &s); int a[s]; One obvious drawback of VLAs is that if s is quite big and the allocation of a could fail.
You can't. Arrays in C have a size that has to be specified when it's declared.
In computer programming, a variable-length array (VLA), also called variable-sized or runtime-sized, is an array data structure whose length is determined at run time (instead of at compile time).
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With