I am attempting to do write a simple program where I take user input two times, and then I print the result of substracting both numbers.
Currently I have detected the following issues with my code (that I am not able to solve):
- It seems like my code can not actually load the variables into the specify memory t1 or t2.
- Once my code executes it displays a huge number, not even close to the operation I am attempting to perform.
.data
x: .word 0 # Allocate size for variables
y: .word 0 # Allocate size for variables
x1: .word 0 # Allocate size for variables
prompt1: .asciiz "First number: "
prompt2: .asciiz "Second number: "
prompt3: .asciiz "Result: "
.text
# Write first prompt
la $a0,prompt1
li $v0,4
syscall
# ReadIn (x1);
li $v0,5 #Prepare to read integer
syscall
sw $v0,x1 # store v0 into x1
# Write second prompt
la $a0,prompt2
li $v0,4
syscall
# ReadIn (x):
li $v0, 5 #Prepare to read integer
syscall
sw $v0, x # Save integer from v0 into X
# Load variables into temporary address
lw $t2, x
lw $t1, x1
# Perform operation
sub $t0, $t2, $t1 # t0 = x-x1
#sw $t0, y # Save into y
move $a0, $t0 # Alternative Save value directly into a0
# lw $a0, y # Load value from y into a0
li $v0, 1 # Print Integer service
syscall # Display result
# Exit
li $v0,10
syscall