- #1
SpiffyEh
- 194
- 0
Homework Statement
I need to compare a user input with a string that's already in the program.
If the operation entered is ‘*’, you should print out the product of the 2 numbers; if the
operation entered is ‘/’, you should print out the quotient and the remainder.
the multiplication and division is implemented using the algorithms
The Attempt at a Solution
The instructor provided code for the comparison of the user entered operation with a string in the code. I'm having issues with this code, maybe I'm just using it wrong. This is the provided code:
Code:
la $a0, operator # puts entered stuff into "operator" string
li, $a1, 3 # reads 3 things: a character, an enter, and a null
li $v0, 8 # load the "read string" syscall number
syscall
la $s2, operator # operator = s2 = value returned
lbu $t4, 0($s2) # loads the character entered by the user
la $t0, addSign # loads the address of the add symbol
lbu $t5, 0($t0) # loads the add symbol
bne $t4, $t5, notAdd #if the charater entered isn't a +, move on
I have the program printing a few lines for input of numbers and such and then I have this:
Code:
la $a0, operation # prints the operation string
li $v0, 4
syscall
la $a0, operator # puts entered data into the operator string
li $a1, 3 # reads 3 things: a character, an enter, and a null
li $v0, 8 # loads the read string syscall number
syscall
la $s2, operator # operator = s2 = value returned
lbu $t4, 0($s2) # loads the character entered bu the user
la $t0, multSign # loads the address of the add symbol
lbu $t5, 0($t0) # loads the add symbol
bne $t4, $t5, notMult # if the character entered isn't a * move on
add $a0, $s0, $0
add $a1, $s1, $0
jal multiplyFunc
add $s3, $v0, $0
add $a0, $s0, $0
li $v0, 1
syscall
la $a0, multSign
li $v0, 4
syscall
add $a0, $s1, $0
li $v0, 1
syscall
la $a0, product
li $v0, 4
syscall
add $a0, $s3, $0
li $v0, 1
syscall
j Exit
no matter what I input it always multiplies and the weird thing is that if i put in the numbers 3 and 2 for examle with the operation / it goes to multiply and it prints "3/2; product = 6" when I'm not printing the user entered operation between the operands, I'm printing the string in the program. I have the strings declared like this:
Code:
product: .asciiz ": product="
operator: .ascii ""
multSign: .asciiz "*"
divSign: .asciiz "/"
I have no idea what I'm doing wrong here, everything besides this works.