1 year ago

#268112

test-img

Dominic Trayer

Why is error exception 7 occuring in my MIPS Code

I'm writing code for my assembly language course and I'm coming across this error although it's still producing the correct output.

"Exception 7 [Bad Data Address]" "Exception occurred at PC=0x00400084"

# MIPS Code for Counting Vowels in a given string Using procedure

#*****************************************************************

.data

str:   .asciiz "The Spirit is willing, but the flesh is weak - The 
Vodka was good, but the Meat was rotten - Out of Sight, out of mind - Invisible insanity, blind and insane"

p1:    .asciiz "Given String: "

Ans:   .asciiz "\n\nNo. of vowels = "


#*****************************************************************

.text

.globl main

main:


# Print p1 and str

li $v0, 4

la $a0, p1

syscall

li $v0, 4

la $a0, str

syscall

# Print Ans

li $v0, 4

la $a0, Ans

syscall


# Prepping Procedure

la $a0, str    # Load str into a0 for procedure (not necessary in this case but usually is)

jal VCount     # Jump and link to procedure

move $a0, $v0  # Moving the No. of vowels into a0

li $v0, 1      # Print the integer

syscall


# Procedure

VCount:

li $s1, 0

li $s0, 0

addi $sp, $sp, -16  # Creating the stack and giving 16 depth

sw $s0, 0($sp)      # Storing registers into stack

sw $s1, 4($sp)

sw $a0, 8($sp)

sw $ra, 12($sp)

move $s1, $a0   # Moving string into s1

Loop:

lb $a0, 0($s1)    # Loading first byte of string in s1 into a0

beqz $a0, End     # a0 = 0 then end loop

jal CheckV        # Jump and link to CheckV procedure 

add $s0, $s0, $v0 # Counter for vowels

addi $s1, $s1, 1  # Navigating through the string 1 letter at a time

j Loop

# After loop

End:

move $v0, $s0

lw $s0, 0($sp)      # Loading registers from stack

lw $s1, 4($sp)

lw $a0, 8($sp)

lw $ra, 12($sp)

addi $sp, $sp, 16 # Countering the -16 stack

jr $ra  # Transfer control

# Checking Vowels

CheckV:

li $v0, 0

beq $a0, 'a', Yes  # Checks for a0 being a vowels and jumps to Yes 
to increase count of vowels

beq $a0, 'e', Yes

beq $a0, 'i', Yes

beq $a0, 'o', Yes

beq $a0, 'u', Yes

beq $a0, 'A', Yes  # Capital vowels

beq $a0, 'E', Yes

beq $a0, 'I', Yes

beq $a0, 'O', Yes

beq $a0, 'U', Yes

jr $ra  # Transfer control if no vowels

Yes:

li $v0, 1  # Increase No. of vowels

jr $ra # Transfer control

# Exit

li $v0, 10

syscall

mips

qtspim

0 Answers

Your Answer

Accepted video resources