Applesausce
Applesausce

Reputation: 43

Crash due to invalid program counter

So my question is how do i fix this error. Is it the structure of my program? or how i went about using the registers?

#JTWILKI - Just The Way I Like It Cooking Assistant 
# Created By: Samuel Buzas
#For CS2028 Sect.002
.data
    preface: .asciiz "Place you Steak in the oven, and kick back. I'll take care of the rest! \n"
    RED: .asciiz    "Steaks Not Ready Yet Come Back Soon! \n"
    YELLOW: .asciiz "Get Ready to Eat!! \n"
    GREEN:  .asciiz "Were Ready to Go!!! \n Get The Steak Out Now, Before it Burns!\n"
    BROWN: .asciiz "Quick It's Starting to Burn!! \n Take it Out!!! \n"
    BLACK: .asciiz "So how about Soup? \n"

.text
main:
# Tell User the program is starting
    li $v0, 4   
    la $a0, preface
    syscall
# Pause for 10 seconds while users places steak in oven, handy MARS Feature
    li $v0, 32
    la $a0, 10000
    syscall
#Display message,Start Cooking
    j red

    addi $s1, $zero, 150000  # Tihs is 2 min 30seconds
    addi $s0, $zero, 0

    #Start The cooking Loop
    jal loop

loop: beq $s1,$s0,exit  # Exit if t9 == t1
    bge $s0, 120000, yellow  # If 30secs from being ready, print yellow warning
    #Otherwise, Increment
    addi $s0, $zero, 1000
    #Pause for 1 sec
    #li $v0, 32
    #la $a0, 1000
    #syscall
    j loop

exit:
#Display message, Cooking complete
    jal green
#Wait 30 Seconds, then overcooking
    li $v0, 32
    la $a0, 30000
    syscall
#Now overcooked
    jal brown
#Wait another 30 seconds
    li $v0, 32
    la $a0, 30000
    syscall
# Now its burned
    jal black

# Terminate Program
    li $v0, 10
    syscall
#Progress Update Functions
red:
    li $v0, 4
    la $a0, RED
    syscall
    jr $ra

yellow:
    li $v0, 4
    la $a0, YELLOW
    syscall
    jr $ra

green:
    li $v0, 4
    la $a0, GREEN
    syscall
    jal beep
    jr $ra

brown:
    li $v0, 4
    la $a0, BROWN
    syscall
    jr $ra

black:
    li $v0, 4
    la $a0, BLACK
    syscall
    jr $ra

beep:
    li $v0, 31
    li $a0, 112
    li $a1, 2000
    li $a2, 10
    li $a3, 100
    syscall
    jr $ra

Upvotes: 1

Views: 1282

Answers (1)

user1274820
user1274820

Reputation: 8144

I think the problem is you are not linking your jump to red.

Change j red to jal red on line 23

Change addi $t0, $zero, 1000 to addi $t0, $t0, 1000 on line 34 to add 1000 to $t0 and store it.

Upvotes: 1

Related Questions