addu $t7, $0, $v0 # Save the return value for later use # addu $t1, $0, $0 # Check the preserved pointer registers # la $t0, __store_GP # lw $t0, 0($t0) # beq $t0, $gp, __check_GP # ori $t1, $t1, 0x400 #__check_GP: # la $t0, __store_SP # lw $t0, 0($t0) # beq $t0, $sp, __check_SP # ori $t1, $t1, 0x200 #__check_SP: # la $t0, __store_FP # lw $t0, 0($t0) # beq $t0, $fp, __check_FP # ori $t1, $t1, 0x100 #__check_FP: # li $t0, 0x57AB7777 # Check the preserved general registers # beq $t0, $s7, __check_S7 # ori $t1, $t1, 0x080 #__check_S7: # li $t0, 0x57AB6666 # beq $t0, $s6, __check_S6 # ori $t1, $t1, 0x040 #__check_S6: # li $t0, 0x57AB5555 # beq $t0, $s5, __check_S5 # ori $t1, $t1, 0x020 #__check_S5: # li $t0, 0x57AB4444 # beq $t0, $s4, __check_S4 # ori $t1, $t1, 0x010 #__check_S4: # li $t0, 0x57AB3333 # beq $t0, $s3, __check_S3 # ori $t1, $t1, 0x008 #__check_S3: # li $t0, 0x57AB2222 # beq $t0, $s2, __check_S2 # ori $t1, $t1, 0x004 #__check_S2: # li $t0, 0x57AB1111 # beq $t0, $s1, __check_S1 # ori $t1, $t1, 0x002 #__check_S1: # li $t0, 0x57AB0000 # beq $t0, $s0, __check_S0 # ori $t1, $t1, 0x001 #__check_S0: # addiu $v0, $0, 4 # la $a0, __chr_Reg # syscall # addiu $v0, $0, 1 # Print "REGMASK\n" # addu $a0, $0, $t1 # syscall # addiu $v0, $0, 4 # la $a0, __chr_Line # syscall # Check the buffer space before the write location # Print either guard okay or overwritten, if overwritten print the incorrent char index la $t0, __MIPSCALL_arg0 la $t1, __MIPSCALL_arg0_mid li $t2, '*' addiu $v0, $0, 4 la $a0, __chr_PGO __check_PreGuard: lbu $t3, 0($t0) addiu $t0, $t0, 1 bne $t2, $t3, __check_PreGuardFail bne $t0, $t1, __check_PreGuard j __check_PreGuardOK __check_PreGuardFail: la $a0, __chr_PGF syscall la $t1, __MIPSCALL_arg0 subu $a0, $t0, $t1 addiu $v0, $0, 1 syscall addiu $v0, $0, 4 la $a0, __chr_Line __check_PreGuardOK: syscall # Check the buffer space after the write location # Print either guard okay or overwritten, if overwritten print the incorrent char index la $t0, __MIPSCALL_arg0_mid addu $t0, $t0, $t7 addiu $t0, $t0, 1 la $t1, __MIPSCALL_arg0_end la $a0, __chr_AGO __check_AftGuard: lbu $t3, 0($t0) addiu $t0, $t0, 1 bne $t2, $t3, __check_AftGuardFail bne $t0, $t1, __check_AftGuard j __check_AftGuardOK __check_AftGuardFail: la $a0, __chr_AGF syscall la $t1, __MIPSCALL_arg0_mid subu $a0, $t0, $t1 addiu $v0, $0, 1 syscall addiu $v0, $0, 4 la $a0, __chr_Line __check_AftGuardOK: syscall # Change all null characters to tildes for printing addiu $v0, $0, 4 # Print "Number of '\0's: " la $a0, __chr_Tild syscall la $t0, __MIPSCALL_arg0_mid addu $t1, $t0, $t7 addiu $t0, $t0, -1 li $t2, '~' addu $a0, $0, $0 __tilde_loop: addiu $t0, $t0, 1 beq $t0, $t1, __tilde_done lbu $t3, 0($t0) bne $t3, $0, __tilde_loop sb $t2, 0($t0) addiu $a0, $a0, 1 __tilde_done: addiu $v0, $0, 1 # Print "COUNT\n" syscall addiu $v0, $0, 4 la $a0, __chr_Line syscall # Put a null terminator into __MIPSCALL_arg0_end (just in case) la $t0, __MIPSCALL_arg0_end sb $0, 0($t0) addiu $v0, $0, 4 # Print "##BUFFER##\n" la $a0, __chr_Hash syscall syscall la $a0, __MIPSCALL_arg0_mid syscall la $a0, __chr_Hash syscall syscall la $a0, __chr_Line syscall la $a0, __chr_Char # Print "Number of Characters: RETVAL\n" syscall addiu $v0, $0, 1 addu $a0, $0, $t7 syscall addiu $v0, $0, 4 la $a0, __chr_Line syscall addi $v0, $0, 10 # terminate program syscall