# This program takes two arguments, both required to be # decimal or hexadecimal integers, and returns their sum. .data plus: .asciiz " + " equals: .asciiz " = " newline: .asciiz "\n" space_character: .asciiz " " usageMessage: .asciiz "\nUsage: \n" .text main: subu $sp,32 # create stack frame sw $ra,28($sp) # save return address sw $s2,24($sp) # save $s2 (y) sw $s1,20($sp) # save $s1 (x) sw $s0,16($sp) # save $s0 move $s0,$a1 # $s0 = argv bne $a0,2,usageError # must have exactly two arguments (both integers) # decode x lw $a0,0($s0) # $a0 = address(1st argument string) = argv[0] jal decode_int move $s1,$v0 # store the result ($v0) in x ($s1) # decode y lw $a0,4($s0) # $a0 = address(2nd argument string) = argv[1] jal decode_int move $s2,$v0 # store the result ($v0) in y ($s2) # print x + y = z move $a0,$s1 # x li $v0,1 # print_int syscall # la $a0,plus # + li $v0,4 # print_string syscall # move $a0,$s2 # y li $v0,1 # print_int syscall # la $a0,equals # = li $v0,4 # print_string syscall # add $a0,$s1,$s2 # z li $v0,1 # print_int syscall # la $a0,newline # \n li $v0,4 # print_string syscall # all_done: lw $ra,28($sp) # lw $s2,24($sp) # lw $s1,20($sp) # lw $s0,16($sp) # addu $sp,$sp,32 # j $ra # # Print the usage error message usageError: la $a0,usageMessage # usage error li $v0,4 # print_str syscall # j all_done # # Converts an integer value from a textual representation to its machine representation # Requires: # a0 the address of the start of the textual representation # Must be a null terminated string. # Returns: # v0 the machine representation of the integer value # -1 => decode error # Project 1: Implement this procedure decode_int: move $v0,$zero # cumulative decoded value = 0 jr $ra # return