1

I am trying to store a integer that i am reading from the user into a array, however when i try to store it into my array my data becomes unaligned.

This first block of code is where i initialize all the data. (Under the 1. is where i am trying to store the integer )

'#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 "-"

Right here is where it becomes unaligned (the sw right after 2.) . The strange thing is that i am doing the exact same thing later (in the third code block) except that i am storing it in the size array.

'#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

At the store word (under the 3. ) it stores the read in integer fine.

        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      

I thought maybe the array was too large but i changed it to 4 (the same size that the other array that worked). But it still was unaligned.

Thanks in advance . This is a project and i know some people don't like helping with stuff like this. But i have done my homework and i cannot find a answer anywhere.

2
  • I figured it out, apparently the two space allocations needed to be right after one another. Otherwise it would unalign the data. I am not sure if this is exactly what is going on here but it fixed my problem. Seems a bit weird does anyone know if this is true for all MIPS programs? Commented Apr 29, 2012 at 3:50
  • Did you bring board_rep down to size, or carry size up to board_rep? Commented Apr 29, 2012 at 4:57

1 Answer 1

1

That doesn't look aligned to me, and if i'm wrong try explicitly aligning it anyway.

Sign up to request clarification or add additional context in comments.

2 Comments

I did do a .align 2 in the code it is just not shown in any of these snippets.
Well if your having alignment issues, posting alignment code might be relevant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.