.text # function max 4 max4: addi $sp, $sp, -4 sw $ra, 0($sp) # a0 and a1 already have the proper values jal max # save $v0 on stack (push) addi $sp, $sp, -4 sw $v0, 0($sp) # set up second call to max one arguments # 3 and 4 move $a0, $a2 move $a1, $a3 jal max # get first argument off stack (pop) lw $a0, 0($sp) addi $sp, $sp, 4 # set up second argument move $a1, $v0 jal max # return from max4 lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra # function max max: # check if a0 is less than a1 slt $v0, $a0, $a1 beq $v0, $zero, a0isbigger addi $v0, $a1, 0 j max_return a0isbigger: addi $v0, $a0, 0 max_return: jr $ra #------------------------------- # M a i n p r o g r a m #------------------------------- main: # save return address on stack addi $sp, $sp, -4 sw $ra, 0($sp) # read four integers from the user and print the maximum # read first integer and put in a0 for # call to max4 li $v0, 5 syscall addi $a0, $v0, 0 # store v0 into t0 # read second integer and put in a1 for call to max4 li $v0, 5 syscall addi $a1, $v0, 0 # put v0 in a1 # read third integer and put in a2 for call to max4 li $v0, 5 syscall move $a2, $v0 # read fourth integer and put in a3 li $v0, 5 syscall move $a3, $v0 jal max4 #put result of max into a0 for syscall to print_int addi $a0, $v0, 0 # get function result out of $v0 li $v0, 1 syscall # Yow! Something bad is going to happen here! What is it? lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra