Solved

Read input from a file using SPIM

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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change Characters to Hex 15 431
Recommended programming language 7 392
Return (ret) value over-writing on x64 8 672
How to Building Five Part Assembly Name for Master Page Inherit 1 475
Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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