Solved

Read input from a file using SPIM

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

822 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