in MIPS, we can allocate memory by using .space of setting $v0 to 9.
.data
arr: .space 12 # array of 12
or
li $v0, 9
li $a0, 12
syscall
I know that both will give me 12 bytes of space, sbrk allocates from heap but I actually do not know what does .space does. Can you explain is there a difference between these two?
Easiest way to see the difference is by looking at your compiled executable in a hex editor. When using .space n
your file size has increased by n
bytes. Try assembling the same program with and without the .space 12
, you'll see 12 extra zeroes in the hexdump of the version with the .space 12
.