0

My question is; How do I store more than one user entered input into a variable without creating an array? When I run the code as I have posted here I get the error "store address not aligned on word boundary." Variable one is store1, variable two is store2. I want to store both separately entered integers into store1, and store2 respectively.

.data

store1: .byte 4                     #Stores data entered by user
store2: .byte 4                     # "                        "
msg: .asciiz "Enter your first decimal number: "
msg2: .asciiz "Enter your second decimal number: "
.text

main:

la $a0, msg #Displays msg
li $v0, 4
syscall

li $v0, 5   #Prompts user to enter an integer
syscall

la $t0, store1  #Loads user input into store1
sw $v0, store1  #Stores user input into store1

la $a0, msg2    #Displays msg2
li $v0, 4
syscall

li $v0, 5   #Prompts user to enter another integer
syscall

la $t1, store2    #My error occurs here 
sw $v0, store2    #If I delete these 3 lines the code compiles with no errors
syscall

li $v0, 10  #Cleanly exits the program 
syscall 
2
  • 1
    You only allocated a byte. If you intend to store bytes, use sb not sw. Conversely, if you want words, use .int or whatever is equivalent in mars. Commented Nov 21, 2019 at 19:35
  • Understood. Using sb corrected the issue. Along with also changing .byte 4 to .int 0 Thank you for your help. Commented Nov 21, 2019 at 21:43

1 Answer 1

1

.byte 4 is one byte with the value 4, not four bytes (a word). So they can't both be word-aligned. You can see this by using the debugger to look at memory contents.

Perhaps you were looking for .skip 4 if MARS allows that GAS pseudo-instruction.

Or like Jester said just use .int 0 or .word 0

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

Comments

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.