I'm having trouble finding where I am going wrong with this program which checks for perfect numbers.
Here are my errors:
I ran it but it's giving me an error saying
Exception occurred at PC=0x00000000
Bad address in text read: 0x00000000
Attempt to execute non-instruction at 0x80000180
## Registers:
## $s3 Holds the number 1
## $s1: Hold the Sum
## $v2: Counter (May not be used)
## $t3: Integer divided by 2
## $t4: Remainder
## $t5: Divisor
## $t6: Temporary check if less than 1
.text
.globl main
main:
li $s3, 1 # Load register $s3 with 1
start:
li $t5, 1 # Set the divisor to zero
li $s1, 0 # Load the Sum to zero
li $t3, 0 # Integer divided by two set to 0
li $t6, 0 # Temporary check if less than 1
li $t0,4 # access prompt
la $a0,prompt # print prompt
syscall
li $v0,5 # code 5 == read integer
syscall # Invoke the operating system.
divu $t3, $a0, 2 # Put the integer divided by 2 in $v3
#BELOW CODE CHECKS IF INTEGER IS <1 and ENDS IF IT IS
sltu $t6,$a0,$s3 # if ( $a0 < $s3 ) (Int < 1)
# $t6 = 1
# else
# $t6 = 0
beq $t6,$s3,end
# THIS IS THE END OF CHECKING IF INTEGER < 1
# BELOW WILL DETERMINE IF THE INTEGER IS PERFECT
run:
remu $t4,$a0,$t5 # divide $a0 by $v5. Put the
# remainder in $v4. Operands are
# unsigned.
beqz $t4,addSum # If the remainder is equal to zero
b check
addSum:
addu $s1, $s1, $t5 # Add the divisor to the Sum
check:
ble $t5, $t3, determine # If register 3 is less than integer/2
addiu $t5, $t5, 1 # Increment the divisor by 1
j run
# END OF DETERMINING IF INTERGER IS PERFECT
determine:
beq $s1, $a0,perfectPrint
b notPerfectPrint
perfectPrint:
li $v0,4 # code 4 == print perfect
la $a0,perfect # $a0 == address of the string
syscall # Invoke the exception handler.
j start # JUMP TO THE START OF THE PROGRAM
notPerfectPrint:
li $v0,4 # code 4 == print string
la $a1,notper # $a1 == address of the not perfect
syscall # Invoke the exception handler.
j start # JUMP TO THE START OF THE PROGRAM
end:
li $v0,10 # code 10 == exit
syscall # Halt the program.
.data
perfect: .asciiz "The number you entered is Perfect."
notper: .asciiz "The number you entered is NOT Perfect."
prompt: .asciiz "Please enter an Integer: "