.text .align 2 .globl main main: li.s $f6, 0.0 #store 0 subu $sp, $sp, 4 #allocate stack space for return address sw $ra, 0($sp) #first head case li $v0, 9 li $a0, 72 syscall move $t1, $v0 #t1 is head of list #Prompt for name li $v0, 4 la $a0, PatientMessage syscall li $v0, 8 move $a0, $t1 li $a1, 64 syscall la $a1, done jal compareStrings bnez $v0, end li $v0, 4 la $a0, infectorMessage syscall li $v0, 6 syscall mov.s $f2, $f0 li $v0, 4 la $a0, label1 syscall li $v0, 6 syscall c.eq.s $f0, $f6 bc1t label2 mov.s $f4, $f0 li.s $f16, 2.0 li.s $f8, 3.14 div.s $f2, $f2, $f16 mul.s $f2, $f2, $f2 mul.s $f2, $f2, $f8 div.s $f4, $f2, $f4 s.s $f4, 64($t1) readLoop: move $t0, $t1 #allocate a new block in heap li $v0, 9 li $a0, 72 syscall move $t2, $v0 li $v0, 4 la $a0, PatientMessage syscall li $v0, 8 move $a0, $t2 li $a1, 64 syscall #need condition to check for "DONE" la $a1, done jal compareStrings bnez $v0, printLoop li $v0, 4 la $a0, infectorMessage syscall li $v0, 6 syscall mov.s $f2, $f0 li $v0, 4 la $a0, label1 syscall li $v0, 6 syscall c.eq.s $f0, $f6 bc1t costToZeroMiddle mov.s $f4, $f0 li.s $f16, 2.0 li.s $f8, 3.14 div.s $f2, $f2, $f16 mul.s $f2, $f2, $f2 mul.s $f2, $f2, $f8 div.s $f4, $f2, $f4 s.s $f4, 64($t2) li $v0, 1 insertionLoop: bnez $v0, firstList lw $t3, 68($t0) beqz $t3, endList l.s $f2, 64($t3) c.lt.s $f2, $f4 bc1t greater c.eq.s $f2, $f4 bc1t equal lw $t0, 68($t0) j insertionLoop label2: s.s $f6, 64($t1) j readLoop costToZeroMiddle: li $v0, 1 mov.s $f4, $f6 s.s $f6, 64($t2) j insertionLoop firstList: li $v0, 0 l.s $f2, 64($t1) c.lt.s $f2, $f4 bc1t greaterFirst c.eq.s $f2, $f4 bc1t equalFirst j insertionLoop greaterFirst: sw $t0, 68($t2) move $t1, $t2 j readLoop equalFirst: la $a0, 0($t2) la $a1, 0($t1) jal compareLessStrings beqz $v1, greaterFirst j insertionLoop endList: sw $t2, 68($t0) move $t0, $t1 j readLoop greater: sw $t2, 68($t0) sw $t3, 68($t2) move $t0, $t1 j readLoop equal: la $a0, 0($t2) la $a1, 0($t3) jal compareLessStrings beqz $v1, greater lw $t0, 68($t0) j insertionLoop compareLessStrings: move $t6, $a0 move $t7, $a1 scrollLoop1: lb $t8, ($t6) lb $t9, ($t7) slt $t5, $t8, $t9 bnez $t5, lessThan slt $t5, $t9, $t8 bnez $t5, greaterThan beqz $t8, checkSecond beqz $t9, greaterThan addi $t6, $t6, 1 addi $t7, $t7, 1 j scrollLoop1 checkSecond: bnez $t9, greaterThan li $v1, 0 #second string less jr $ra lessThan: li $v1, 0 #first string less jr $ra greaterThan: li $v1, 1 #second string less jr $ra compareStrings: move $t6, $a0 move $t7, $a1 scrollLoop2: lb $t8, ($t6) lb $t9, ($t7) beqz $t8,checkSecond2 beqz $t9, notEqual bne $t8, $t9, notEqual addi $t6, $t6, 1 addi $t7, $t7, 1 j scrollLoop2 notEqual: li $v0, 0 jr $ra checkSecond2: bnez $t9, notEqual li $v0, 1 trimming: li $t5, 10 lb $t4, 0($a0) beq $t4, $t5, replaceTrimming beqz $t4, doneTrimming addi $a0, $a0, 1 j trimming replaceTrimming: sb $zero, 0($a0) doneTrimming: jr $ra printLoop: #print name li $v0, 4 la $a0, 0($t1) jal trimming la $a0, 0($t1) syscall #print space li $v0, 4 la $a0, space syscall #print per li $v0, 2 l.s $f12, 64($t1) syscall #print new line li $v0, 4 la $a0, nln syscall lw $t1, 68($t1) beqz $t1, end j printLoop end: lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra .end main .data PatientMessage: .asciiz "Please enter patient:" infectorMessage: .asciiz "“Please enter infecter:" done: .asciiz "DONE\n" space: .asciiz " " nln: .asciiz "\n"