Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the program in MIPS that reads a string representing an attendance record

ID: 3590496 • Letter: W

Question

Write the program in MIPS that reads a string representing an attendance record for a student The record only contains the following three characters: 1. 'A' Absent. 2. 'L': Late. 3. 'P: Present A student could be rewarded if his attendance record doesn't contain more than one 'A (absent) or more than two consecutive 'L' (late) You need to return (print) whether the student could be rewarded according to his attendance record Example: Input: "PPALLP Output: True Example 2: Input: "PPALLL" Output: False

Explanation / Answer

.data

attendance: .space 20

str1: .asciiz "Enter the attendence record of max 20 days"

pass: .asciiz "True"

fail: .asciiz "False"

.text

.globl main

main:

la $a0,str1 #prompts the message

li $v0,4

syscall

la $a0,attendance #reads the input and store in buffer

li $v0,8

syscall

la $t1,buffer

li $t3,0

li $t5,0

outer_loop:

lb $t2,($t1)

beq $t2,0,exit #record completed

bne $t2,'L',absent_check #first consecutive check

add $t1,$t1,1 #selecting next element

lb $t2,($t1)

bne $t2,'L',absent_check #second consecutive check

add $t1,$t1,1

lb $t2,($t1)

bne $t2,'L',absent_check #third consecutive check

li $t5,1 #consecutive late

absent_check:

bne $t2,'A',skip_counter

addi $t3,$t3,1 #absent count

skip_counter:

add $t1,$t1,1 #next element

j loop

exit:

li $t4,1 #check for two consecutive lates

bne $t4,$t5,TRUE

li $t4,2 #check for absent

blt $t3,$t4,TRUE

FALSE:

la $a0,fail #prompts the FALSE

li $v0,4

syscall

li $v0,10

syscall

TRUE:

la $a0,pass #prompts the true

li $v0,4

syscall

li $v0,10

syscall