Solved

Read input from a file using SPIM

Posted on 2003-11-20
1
430 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

630 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