# MIPS Assembly: Attendance System (Command-Line Version) # # This program implements a simple command-line attendance tracking system. # It allows a user to view attendance records and mark students as # present, absent, or late. # # This version is compatible with most online MIPS simulators. .data # --- Constants for Attendance Status --- PRESENT: .word 1 # Represents 'Present' status ABSENT: .word 2 # Represents 'Absent' status LATE: .word 3 # Represents 'Late' status # --- Student Data Structure --- # We will use parallel arrays to store student information. # student_ids: An array of words to store unique student IDs. # student_status: An array of words to store the attendance status for each student. # The student at index `i` in `student_ids` has their status at index `i` in `student_status`. student_ids: .word 101, 102, 103, 104, 105, 106, 107, 108, 109, 110 # Example student IDs student_status: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 # Initial status (0 for 'Not Marked') STUDENT_COUNT: .word 10 # Total number of students # --- User Interface Strings --- welcome_msg: .asciiz "\n*** MIPS Attendance Management System ***\n" menu: .asciiz "\nPlease select an option:\n 1. Mark Attendance\n 2. View Attendance Sheet\n 3. Exit\n\nYour choice: " prompt_student_id: .asciiz "Enter Student ID to mark: " prompt_status: .asciiz "Enter status (1=Present, 2=Absent, 3=Late): " invalid_choice_msg: .asciiz "Error: Invalid choice. Please try again.\n" invalid_id_msg: .asciiz "Error: Student ID not found.\n" invalid_status_msg: .asciiz "Error: Invalid status code.\n" update_success_msg: .asciiz "Attendance marked successfully!\n" exit_msg: .asciiz "\nExiting the program. Goodbye!\n" sheet_header: .asciiz "\n--- Attendance Sheet ---\n" student_id_label: .asciiz "Student ID: " status_label: .asciiz " | Status: " status_not_marked: .asciiz "Not Marked\n" status_present: .asciiz "Present\n" status_absent: .asciiz "Absent\n" status_late: .asciiz "Late\n" newline: .asciiz "\n" .text .globl main #----------------------------------------------------------------------- # main: The main entry point of the program. # Displays the main menu and directs the user based on their choice. #----------------------------------------------------------------------- main: # Display welcome message li $v0, 4 la $a0, welcome_msg syscall main_loop: # Display the menu li $v0, 4 la $a0, menu syscall # Get user's choice li $v0, 5 syscall move $t0, $v0 # Store user's choice in $t0 # Branch based on user choice beq $t0, 1, mark_attendance_section # Option 1: Mark Attendance beq $t0, 2, view_attendance_section # Option 2: View Attendance beq $t0, 3, exit_program # Option 3: Exit # Handle invalid choice li $v0, 4 la $a0, invalid_choice_msg syscall j main_loop #----------------------------------------------------------------------- # mark_attendance_section: Handles the logic for marking a student's attendance. # Prompts for student ID and desired status, then updates the record. #----------------------------------------------------------------------- mark_attendance_section: # Prompt for Student ID li $v0, 4 la $a0, prompt_student_id syscall li $v0, 5 syscall move $s0, $v0 # Store the target student ID in $s0 # Prompt for Status li $v0, 4 la $a0, prompt_status syscall li $v0, 5 syscall move $s1, $v0 # Store the desired status in $s1 # --- Validate the status code --- lw $t1, PRESENT lw $t2, ABSENT lw $t3, LATE beq $s1, $t1, find_student # Status is Present beq $s1, $t2, find_student # Status is Absent beq $s1, $t3, find_student # Status is Late # If status is not 1, 2, or 3, it's invalid li $v0, 4 la $a0, invalid_status_msg syscall j main_loop find_student: # --- Find the student's index --- la $t0, student_ids # $t0 = address of student_ids array lw $t1, STUDENT_COUNT # $t1 = number of students li $t2, 0 # $t2 = loop counter (i) find_loop: beq $t2, $t1, student_not_found # If i == STUDENT_COUNT, student not found # Load the current student ID from the array lw $t3, 0($t0) # $t3 = student_ids[i] # Check if it matches the target ID beq $t3, $s0, student_found # If student_ids[i] == target_id, we found it # Move to the next student addi $t0, $t0, 4 # Move to the next element in student_ids addi $t2, $t2, 1 # i++ j find_loop student_not_found: li $v0, 4 la $a0, invalid_id_msg syscall j main_loop student_found: # $t2 now holds the index of the student # Update the corresponding status in student_status array # Calculate the address of student_status[i] la $t4, student_status # $t4 = base address of student_status sll $t5, $t2, 2 # $t5 = i * 4 (offset) add $t4, $t4, $t5 # $t4 = address of student_status[i] # Store the new status sw $s1, 0($t4) # student_status[i] = new_status # Display success message li $v0, 4 la $a0, update_success_msg syscall j main_loop #----------------------------------------------------------------------- # view_attendance_section: Displays the full attendance sheet. # Iterates through all students and prints their ID and current status. #----------------------------------------------------------------------- view_attendance_section: # Print header li $v0, 4 la $a0, sheet_header syscall # Initialize loop variables la $t0, student_ids # $t0 = address of student_ids la $t1, student_status # $t1 = address of student_status lw $t2, STUDENT_COUNT # $t2 = number of students li $t3, 0 # $t3 = loop counter (i) view_loop: beq $t3, $t2, view_loop_end # If i == STUDENT_COUNT, end loop # --- Print "Student ID: " --- li $v0, 4 la $a0, student_id_label syscall # --- Print the student ID --- li $v0, 1 lw $a0, 0($t0) # Load student_ids[i] syscall # --- Print " | Status: " --- li $v0, 4 la $a0, status_label syscall # --- Print the status string --- lw $t4, 0($t1) # Load student_status[i] into $t4 # Load status constants for comparison lw $t5, PRESENT lw $t6, ABSENT lw $t7, LATE beq $t4, $t5, print_present beq $t4, $t6, print_absent beq $t4, $t7, print_late # Default case: Status not marked li $v0, 4 la $a0, status_not_marked syscall j next_student print_present: li $v0, 4 la $a0, status_present syscall j next_student print_absent: li $v0, 4 la $a0, status_absent syscall j next_student print_late: li $v0, 4 la $a0, status_late syscall j next_student next_student: # Move to the next student in both arrays addi $t0, $t0, 4 # Next ID addi $t1, $t1, 4 # Next status addi $t3, $t3, 1 # i++ j view_loop view_loop_end: j main_loop #----------------------------------------------------------------------- # exit_program: Terminates the program execution. #----------------------------------------------------------------------- exit_program: # Print exit message li $v0, 4 la $a0, exit_msg syscall # Terminate the program li $v0, 10 syscall