# # using integer variables # read two ints and store in num1 and num2 # add them (from the variables) and store result in num3 # print the sum (from the variable) # .data num1: .word 0 num2: .word 0 num3: .word 0 inlabel: .asciiz "\nA number: " outlabel: .asciiz "\nThe result: " .globl main .text main: lui $t0, 0x1001 # $t0 <- base addr of data segment # read two ints, store in variables li $v0, 4 # syscall code to print string addi $a0, $t0, 12 # add 12 to $t0 to get addr of prompt syscall # print prompt li $v0, 5 # syscall code to read int syscall # read first int (stored in $v0) sw $v0, 0($t0) # store first int in num1 li $v0, 4 # syscall code to print string addi $a0, $t0, 12 # add 12 to $t0 to get addr of prompt syscall # print prompt li $v0, 5 # syscall code to read int syscall # read next int (stored in $v0) sw $v0, 4($t0) # store first int in num2 # add the ints and store sum in var lw $t1, 0($t0) # $t1 <- num1 lw $t2, 4($t0) # $t2 <- num2 add $t3, $t1, $t2 # $t3 <- num1 + num2 sw $t3, 8($t0) # store the sum in num3 # print the sum li $v0, 4 # syscall code to print string addi $a0, $t0, 24 # add 24 to $t0 for addr of result msg: # 23 for nums & inlabel, 1 for null # byte at end of inlabel syscall # print result msg lw $a0, 8($t0) # $a0 <- num3 li $v0, 1 # syscall code to print an int syscall # print num3 li $v0, 10 # syscall code to exit from program syscall # return