MIPS Assembly Language invalid program counter value error

38 Views Asked by At

Please help, I get this error all the time and have been able to 'mysteriously' fix the issue. However i'm continuously getting this error:

Go: running mips1.asm

Error in : invalid program counter value: 0x00000000

Go: execution terminated with errors.

this is my current code:

.data
array:                .space 40      # 10 integers * 4 bytes = 40 byte array
newline:              .asciiz "\n"
userPrompt:           .asciiz "Enter integer: "
print_sum_statement:  .asciiz "Sum: "
print_avg_statement:  .asciiz "Average: "
print_max_statement:  .asciiz "Maximum: "
print_min_statement:  .asciiz "Minimum: "
print_even_statement: .asciiz "Even: "
print_odd_statement:  .asciiz "Odd: "
.text
main: 
    # Setting up loop
    li $t0, 0           # Loop counter
    la $t1, array       # Load the base address of the array into $t1
    li $t2, 0    

    # Collect user input
    jal intRead         # Jump to function to read in array
    # Compute the sum of user input
sum_print:
    li $v0, 4
    la $a0, print_sum_statement
    syscall

    jal sum_calc       # Calculate sum
    move $t2, $v0      # Move sum to $t2

    li $v0, 1
    move $a0, $v0      # Print the sum 
    syscall

    li $v0, 4
    la $a0, newline
    syscall
    # Exit
    li $v0, 10
    syscall
# Read In Array Loop
intRead:
    sw $ra, 0($sp)     # Push caller address into stack 
    addi $sp, $sp, -4  # Move address pointer up
    
    li $t2, 0          # Integer counter

intRead_loop:
    beq $t2, 10, intRead_exit   # Break when count reaches 10

    # Prompt for user input
    li $v0, 4
    la $a0, userPrompt
    syscall

    # Read in user input
    li $v0, 5
    syscall 

    beq $v0, -9, intRead_exit

    sw $v0, 0($t1)      # Store word (user input) into the array at the first open location
    
    # Increment variables
    addi $t1, $t1, 4    # Increment array address by 4 (4 bytes)
    addi $t0, $t0, 1    # Increment loop counter by 1 
    addi $t2, $t2, 1    # Increment integer count by 1

    j intRead_loop

intRead_exit:   # Exit the function
    move $s0, $t2     # Save the number of items in array    
    lw $ra, 0($sp)
    addi $sp, $sp, 4
    jr $ra  
# Sum Calculation
sum_calc:
    sw $ra, 0($sp)     # Push caller address into stack 
    addi $sp, $sp, -4  # Allocate space on the stack for $ra

    li $t0, 0          # Reset sum_loop counter   
    li $t3, 0          # Initialize sum of array

    la $t1, array

sum_loop:
    beq $t0, $t2, sum_exit   # Exit loop when sum_loop counter equals number of items
    
    lw $t4, 0($t1)      # Load the integer value into $t4
    add $t3, $t3, $t4   # Add integer to sum
    addi $t1, $t1, 4    # Move to next integer in array
    addi $t0, $t0, 1    # Increment sum_loop counter

    j sum_loop

sum_exit:
    move $v0, $t3       # Move sum to $v0
    
    lw $ra, 0($sp)      # Pop caller's address 
    addi $sp, $sp, 4    # Move address pointer back down
    jr $ra              # Return to caller function

I believed it to be due to not storing the values correctly for accessing them in different functions but i thought i fixed that as well. I do not understand what I'm doing incorrectly, please enlighten me for future issues.

0

There are 0 best solutions below