Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:02:35+00:00 2026-06-12T11:02:35+00:00

I am trying to take 4 numbers from the keyboard and store it to

  • 0

I am trying to take 4 numbers from the keyboard and store it to an array. I have come up with the following code however when I try and print the first number in the array it prints 0. Why is it not printing the first value in the array?

main: 
li $v0, 5 # read integer 
syscall
add $s0, $v0, $zero #store input1 to s0

li $v0, 5 # read integer 
syscall
add $s1, $v0, $zero #store input2 to s0

li $v0, 5 # read integer 
syscall
add $s2, $v0, $zero #store input3 to s0

li $v0, 5 # read integer 
syscall
add $s3, $v0, $zero #store input4 to s0

.data 
list:   $s0, $s1, $s2, $s3 #set array from keyboard values
.text

#get the array into a register
la $t3, list # put address of list into $t3
lw $t4, 0($t3) # get the value from the array cell

li $v0, 1 # print integer 
move $a0, $t4 # what to print is stored at $s1 
syscall # make system call


exit:    
    li $v0, 10 # exit system call 
syscall

Idea taken from:
http://www.cs.pitt.edu/~xujie/cs447/AccessingArray.htm
But they are using hard-coded ints instead of values saved to registers from keyboard.
Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:02:37+00:00Added an answer on June 12, 2026 at 11:02 am

    This:

    .data 
    list:   $s0, $s1, $s2, $s3 #set array from keyboard values
    .text
    

    does not work this way. You need sw to store the values of registers to memory.

    So, at the start of the program, reserve some space to store the values:

    .data 
    list:  .space 16
    .text
    

    Then, after you read the values, store them with sw:

    sw $s0, list
    sw $s1, list + 4
    sw $s2, list + 8
    sw $s3, list + 12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that I am trying to take a set of numbers
I am trying to take numbers from three EditText boxes that the user fills
I'm trying to write a piece of code that will do the following: Take
i am trying to get the sum of even numbers from a recursive array
I have a datagridview with 9 columns. I am simply trying take the value
I have a text area (from which I take a number) and button to
Hi I am trying to do the following: I have a process which can
I am trying to get a decimal input from the keyboard, and it is
I am trying to create a linked list that will take the input from
I'm trying to create a game. I have a list. I want to take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.