Reputation: 109
I'm trying to write a program in MARS (MIPS Assembler and Runtime Simulator) that will take two integers from the user and then either add or multiply based on what the user chooses to do. Anyways, I haven't gotten too far into the program yet, however I really can't figure out why it won't print my 3rd prompt out. Can you please help me?
.data
prompt1: .asciiz "Enter an Integer!"
prompt2: .asciiz "Enter Another Integer!"
prompt3: .asciiz "Would you like to add or multiply? (+ for add, * for multiply)"
resultout: .asciiz "The result is:"
.text
main:
la $a0, prompt1
li $v0, 4
syscall
li $v0, 5
syscall
add $t0, $v0, $zero
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
add $t1, $v0, $zero
la $a0, prompt3
li $v0, 12
syscall
li $v0, 11
syscall
add $t2, $v0, $zero
Upvotes: 1
Views: 293
Reputation:
To print the prompt and fetch the single character I think you need to load immediate to $v0
the correct value for the syscall
. According to the MARS 4.5 Help file, the Table of Available Services suggest that your code should be something like this from line 24 on:
la $a0, prompt3
li $v0, 4
syscall
li $v0, 12
syscall
That is, you want to "print string" whatever is in prompt3
and then "read character" to get the single character. The first syscall
you make is 12, which is "read character" so it was waiting for you to input something.
I recommend putting magic numbers like 4 and 12, which represent specific system calls, into the code as constants:
.eqv SYS_PRINT_STRING 4
[...]
li $v0, SYS_PRINT_STRING
Upvotes: 1