0

i am working on a class project and what i wan to do, is ask theuserfor 2 integers, when prompted by the message"please enter an integer:" and alsoto enter a character when the message"please enter an operator(+, *, -, /)" pops up. can someone pleaselook at this code and tell me what i am doing wrong? the first instruction prints but i get an erro message with the character input.

really appreciate it

.data
prompt: .asciiz "Please enter an integer\n"
message: .asciiz "Please enter an operator (+, - , * , / ):"
usercharacter:  .space 2
.text
.globl main

main:
li $v0, 4           #system call code for printing a string is 4
la $a0, prompt      #adress of string is argument 0, to print string  

syscall             # telling the system to execute the action

li  $v0, 5              # system call for reading and displaying input
syscall             
move $t1, $v0               # store input one into register $a1

li $a0, message
li $v0, 4
syscall

la $a0,usercharacter
li $a1, 2     #allocating a space for 2 caracters 
li $v0 12
syscall

li $v0, 4           #system call code for printing a string is 4
la $a0, prompt      #adress of string is argument 0, to print string  

syscall             # telling the system to execute the action

li  $v0, 5              # system call for reading and displaying input
syscall                 
move $t2,$v0                #print the prompt message for the user to input 
li,$v0,10
syscall
TINA15
  • 13
  • 1
  • 10
  • 1
    _"i get an erro message"_ **What** error message? Also, the way you're using system call 12 (`read_character`) leads me to believe that you've misunderstood what it does. – Michael Oct 28 '16 at 08:51
  • the error message is " attempt to execute non-instruction at 0x0040003c". What my code is trying to do,is read a character from a user. i read somewhere that the code for that is a 12.Maybe i am not using it right. Can you please tell me how to use it? Thanks for your response. – TINA15 Oct 28 '16 at 10:40
  • The code you've posted doesn't look like it would even assemble. There's no label `main` for example. For info on the system calls available in SPIM, [see this](https://www.doc.ic.ac.uk/lab/secondyear/spim/node8.html). – Michael Oct 28 '16 at 10:43
  • my bad, i guess i left it out when i was transferring the code.thanks – TINA15 Oct 28 '16 at 10:46

1 Answers1

0

I hope this helps,

The questions what to input 1 integers and one operator (+, - , * , / ) and then the second integer.Here is the code.

.data

input1: .asciiz "Please enter an integer: "
input2: .asciiz "Please enter an operator(+, -,  *, /): "
input3: .asciiz "Enter second value: "
newline:    .asciiz "\n"

.text
.globl main
main:

li  $v0, 4
la $a0, input1
syscall                           #printing input 1

li $v0, 5
syscall
                              #reading and storing first value
move $t1, $v0 

li $v0, 4
la $a0, input2
syscall                            #printing  input 2

li $v0, 12
syscall                          #reading operator
move $t9, $v0                    #storing operator

li $v0, 4
la $a0, newline
syscall

li $v0, 4
la $a0, input3
syscall                            #printing input 3
li $v0, 5
syscall
                                   #reading and storing second value

exit:
li $v0, 10
syscall                             # ending main

Thanks

TINA15
  • 13
  • 1
  • 10