I got this problem for an assignment in which we have put these number in an array and add them without using a loop. I have solved this problem but .space is confusing me. By making .space 20 do i make space for 5 words or is it doing something else.
.data array: .space 20 .text addi $s0, $zero, 2 addi $s1, $zero, 12 addi $s2, $zero, -5 addi $s3, $zero, 7 addi $s4, $zero, 4 addi $t0, $zero,0 #index initialized at 0 sw $s0,array($t0) addi $t0, $t0, 4 sw $s1,array($t0) addi $t0, $t0, 4 sw $s2,array($t0) addi $t0, $t0, 4 sw $s3,array($t0) addi $t0, $t0, 4 sw $s4,array($t0) addi $t0, $t0, 4
.space Len
directive instructs the assembler to reserve Len bytes.
As every word has 4 bytes, when Len is 20 you are instructing the assembler to reserve 5 words.
For example if you have
.data
array: .space 20
other_data: .asciiz 'This is other data'
then other_data
will be 20 bytes after array
address.
Due to architectural constraints in MIPS you may need to also instruct the assembler to align the reserved memory (.align 2
) before your array label if you want to access on a word-by-word basis (in your particular example you would not need it, it should be already aligned).