Solved

Read input from a file using SPIM

Posted on 2003-11-20
1
397 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
1 Comment
 
LVL 5

Accepted Solution

by:
mtmike earned 100 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now