为什么我的 MIPS 代码中出现错误异常 7
我正在为我的汇编语言课程编写代码,尽管它仍然产生正确的输出,但我遇到了这个错误。
“异常 7 [错误数据地址]” “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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论