2012-04-29 101 views
1

我想存储一个整数,我正在从用户读取到数组中,但是当我尝试将其存储到我的数组中时,我的数据变为未对齐。MIPS汇编程序内存对齐问题(包括详细的代码)

这第一块代码是我初始化所有数据的地方。 (根据1就是我试图存储整数)

'#Constants 
P_INT  = 1  #Syscall to print integer(value) 
P_STRING  = 4  #Syscall to print a string(addr) 
P_CHAR  = 11  #Syscall to print a char(char) 
R_INT  = 5  #Syscall to read a integer(none) 
EXIT   = 10  #Exit program(none) 

'#Data 
     .data 
newline: 
     .asciiz "\n"   

'#Space for the bored. 

1. 
board_rep: 
     .space  578 

'#The current node to be read in 
cur_node: 
     .word  0 

'#Size of the bored 
size: 
     .space  4 
'#Plus sign 
plus: 
     .asciiz "+" 
'#dash 
dash: 
     .asciiz "-" 

就在这里,它(2右后SW)变得不对齐。奇怪的是,我在后面(在第三个代码块)完成同样的事情,除了我将它存储在大小数组中。

'#Grabs user input for the bored and stores it 
get_board_rep: 


     li  $v0,R_INT  '#Read next node and store it  
     syscall 
2. 
     sw  $v0,0($s1) 

     addi  $s1,$s1,4 ' #Increment next node addr 

     lw  $a0,0($s1) 
     j  prnt_node 

在存储字(下3),它存储在整数精细读。

 la  $s0, size  ' #Store the variable addr's 
     la  $s1, board_rep 

     li  $v0,R_INT  ' #Get user input(size of bored) 
     syscall 
3. 
     sw  $v0,0($s0)  ' #Store the size of bored 


     jal  get_board_rep  

我想也许数组太大,但我把它改成4(同尺寸是:工作的其他阵列)。但它仍然没有对齐。

在此先感谢。这是一个项目,我知道有些人不喜欢帮助像这样的东西。但我已经完成了我的功课,我无法在任何地方找到答案。

+0

我想明白了,显然这两个空间分配需要彼此正确。否则,它会取消对齐数据。我不确定这是否是这里发生的事情,但它解决了我的问题。似乎有点奇怪,有人知道这是否适用于所有MIPS程序? – Man 2012-04-29 03:50:31

+0

您是否已经将board_rep降低到最大尺寸,或者尺寸达到board_rep? – Musa 2012-04-29 04:57:18

回答

1

这看起来并不对齐我,如果我错了尝试明确调整它。

+0

我在代码中做了一个.align 2,它只是没有显示在这些代码片段中。 – Man 2012-04-29 02:54:02

+0

那么如果你有对齐问题,发布对齐代码可能是相关的 – Musa 2012-04-29 03:02:34