# MIPS Program which obtains three inputs from the user
# and prints the result of the expression (a+b)-c

.data
prompt: .asciiz "Enter an integer value: \n"
answer: .asciiz "The result of the expression (a+b)-c is: "

.text
main:
    jal get_integer     # call procedure to get a
    move $s0, $v0       # put returned value in "save" register

    jal get_integer     # call procedure to get b
    move $s1, $v0       # put returned value in "save" register

    jal get_integer     # call procedure to get c
    move $s2, $v0       # put returned value in "save" register

    move $a0, $s0       # move three input values to argument registers
    move $a1, $s1
    move $a2, $s2
    jal compute_expression # call procedure to get (a+b)-c
    move $s0, $v0       # put returned value in "save" register

    li $v0, 4           # print leading string before solution
    la $a0, answer
    syscall

    li $v0, 1           # system call to print an integer (the result)
    move $a0, $s0
    syscall

    li $v0, 10          # system call to exit
    syscall

# Function that prompts the user to enter an integer value.
# Read and return the integer. It takes no parameters.
get_integer:
    li $v0, 4           # system call to print a string
    la $a0, prompt      # address of string is argument 0 to print_string
    syscall

    li $v0, 5           # get ready to read in integers
    syscall             # system call waits for input, puts value in $v0

    jr $ra

# Function that computes (a + b) - c. It takes three parameters:
#   $a0 -- a
#   $a1 -- b
#   $a2 -- c
compute_expression:
    add $t0, $a0, $a1   # t0 <-- (a + b)
    sub $t1, $t0, $a2   # t1 <-- (a + b) - c
    move $v0, $t1
    jr $ra

