what does .space do in mips?

佐手、 提交于 2019-12-08 04:53:46

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/33105872/what-does-space-do-in-mips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!