.space在mips中有什么作用? [英] what does .space do in mips?
问题描述
我遇到了一个分配问题,在该分配中,我们将这些数字放入了一个数组中,并在不使用循环的情况下将它们相加.我已经解决了这个问题,但是.space使我感到困惑.通过设置.space 20,我可以为5个单词腾出空间还是在做其他事情.
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
指令指示汇编程序保留Len字节.
由于每个字都有4个字节,因此当Len为20时,您将指示汇编程序保留5个字.
.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.
例如,如果您有
.data
array: .space 20
other_data: .asciiz 'This is other data'
然后other_data
将是array
地址之后的20个字节.
then other_data
will be 20 bytes after array
address.
由于MIPS中的体系结构限制,如果您想逐字访问(在您的特定示例中,您可能还需要指示汇编器在数组标签之前对齐保留的内存(.align 2
)).不需要它,它应该已经对齐了.
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).
这篇关于.space在mips中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!