######################################################################## # A simple MIPS demo program # Filename: mipsdemo2.s # Author: L.Aamodt # Version: 1/23/22 # Processor: MIPS # Notes: for execution using the SPIM simulator # Implements this functionality: # If (X < Y) # display X on the console # Z = X # else # display Y on the console # Z = Y # where X and Y are integers ######################################################################## .data arrayD: .space 100 # 100 bytes (25 words) reserved for arrayD varX: .word 6 # (array not used in this program) varY: .word 10 varZ: .word 0 str1: .asciiz "X = " str2: .asciiz "Y = " .text # t0 is X # t1 is Y # t2 contains the address of X # t3 contains the address of Y # t4 contains the address of Z # t5 temporary value main: la $t2, varX # get address of X la $t3, varY # get address of Y la $t4, varZ # get address of Z lw $t0, 0($t2) # get X lw $t1, 0($t3) # get Y if: slt $t5, $t0, $t1 # check to see if X < Y beq $t5, $0, else sw $t0, 0($t4) # Z = X li $v0, 4 # print a string function code la $a0, str1 # load address of string syscall li $v0, 1 # print an integer function code add $a0, $t0, $0 # a0 = X syscall j exit else: sw $t1, 0($t4) # Z = Y li $v0, 4 # print a string function code la $a0, str2 # load address of string syscall li $v0, 1 # print an integer function code add $a0, $t1, $0 # a0 = Y syscall exit: addi $v0, $0, 10 # terminate the program with system call #10 syscall