        .data
solution_text:
        .asciiz "Solution: "
saved_text:
        .asciiz "Saved: "
newline:
        .asciiz "\n"
        
        .text
# $a0: first integer
# $a1: second integer
# Returns ($a0 + $a0) + ($a1 + $a1) in $v0.
# Uses $s0 and $s1 as part of this process.  Because these are preserved
# across a call, add_ints must save their values internally
add_ints:
        # save $s0 and $s1 on the stack
        addi $sp, $sp, -8 # make room for two words
        sw $s0, 4($sp)    # non-zero offset
        sw $s1, 0($sp)

        # calculate the value
        add $s0, $a0, $a0
        add $s1, $a1, $a1
        add $v0, $s0, $s1

        # because $t0 isn't preserved, we can modify it directly
        li $t0, 2
        
        # restore the registers and return
        lw $s1, 0($sp)
        lw $s0, 4($sp)
        addi $sp, $sp, 8
        jr $ra

main:
        # save 1 in $t0
        li $t0, 1

        # call add_ints.  Because we want to save the value of $t0
        # in this case, and because it's not preserved across a call,
        # it is our responsibility to store it on the stack and restore
        # it after add_ints finishes
        addi $sp, $sp, -4
        sw $t0, 0($sp)

        # setup the call and make it
        li $a0, 3
        li $a1, 7
        jal add_ints

        # restore $t0
        lw $t0, 0($sp)
        addi $sp, $sp, 4

        # print out the solution prompt
        move $t1, $v0
        li $v0, 4
        la $a0, solution_text
        syscall

        # print out the solution itself
        li $v0, 1
        move $a0, $t1
        syscall

        # print out a newline
        la $a0, newline
        li $v0, 4
        syscall

        # print out the prompt for the saved value
        la $a0, saved_text
        li $v0, 4
        syscall

        # print out the saved value
        move $a0, $t0
        li $v0, 1
        syscall

        # exit
        li $v0, 10
        syscall
        
