Solved

Read input from a file using SPIM

Posted on 2003-11-20
1
422 Views
Last Modified: 2008-03-10
Hi,
I have a file where I need to read the data from? I am doing
      .data
temp:      .word      32
      .text
      .globl main

        li $v0,5      #read from an input
      syscall
      
      lw $a0,temp
      sw $a0,$v0  <<<<<< syntax error here.
      li $v0,1
      syscall

I dont understand why I keep getting syntax error here. I am trying to store the value read in the memory and then print the value. Can any one tell me where I am going wrong and how should I go about fixing the above problem.
Thanx
0
Comment
Question by:axshay123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
mtmike earned 100 total points
ID: 9799975
The "sw" instructions expects an address not a register. SPIM always gives you a "syntax error" and forgets to tell you what you did wrong. Try:

.data

temp:  .word 32

.text
.globl main

main:
      li $v0,5
      syscall ; # read input into $v0

      la $a0,temp # load address of temp
      sw $v0,($a0) # store $v0 in temp

      move $a0,$v0 # copy $v0 to $a0
      li $v0,1
      syscall # print number in $a0

You can also use

sw $v0,temp

instead of

la $a0,temp
sw $v0,($a0)

to store $v0 into temp
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question