嘿伙计们,我正在为一个 comp 编写一个 mips 程序。拱。我正在上的课。教授要求我们:
提示输入 65 到 90 之间的四个整数,然后打印出与输入整数对应的 4 个 ASCII 字符的字符串。例如,如果用户输入“65 66 67 和 68”,程序将打印“ABCD”。假设我们只有 syscall #4 而没有 syscall #11。
我在下面添加了我的代码,每当我运行它时,我都会在 0x004000e8 处得到运行时异常:地址超出范围 0x00000041 作为错误。对我做错的任何帮助都会很棒,谢谢。
.data #data Segment
stringMsg: .asciiz "Enter 4 integers that are between 65-90, inclusive: "
#Stores string in data segment + null terminator
alphaTable: .byte 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
.text
string:
li $v0, 4 #Syscall #4 prints string
la $a0, stringMsg #Loads address of string "inputMsg"
syscall #Prints inputMsg
li $v0, 5 #Syscall #5 reads integer
syscall #reads inputted val into $v0
la $s0, ($v0) #save first number into s0
li $v0, 5 #Syscall #5 reads integer
syscall #reads inputted val into $v0
la $s1, ($v0) #save second number into s1
li $v0, 5 #Syscall #5 reads integer
syscall #reads inputted val into $v0
la $s2, ($v0) #save third number into s2
li $v0, 5 #Syscall #5 reads integer
syscall #reads inputted val into $v0
la $s3, ($v0) #save fourth number into s3
sub $s0, $s0, 65 #Subtract 65 from the 4 # to get correlating value in array
sub $s1, $s1, 65
sub $s2, $s2, 65
sub $s3, $s3, 65
la $s4, alphaTable #Loads table into $s4 (used to get index val)
la $s5, alphaTable #Loads table into $s5 (used to reset index val)
add $s5, $s5, $s0
li $v0, 4 #Syscall #4 prints string
lb $a0, ($s5) #Loads address of string "inputMsg"
syscall #Prints inputMsg
la $s5, ($s4)
add $s5, $s5, $s1
li $v0, 4 #Syscall #4 prints string
lb $a0, ($s5) #Loads address of string "inputMsg"
syscall #Prints inputMsg
la $s5, ($s4)
add $s5, $s5, $s2
li $v0, 4 #Syscall #4 prints string
lb $a0, ($s5) #Loads address of string "inputMsg"
syscall #Prints inputMsg
la $s5, ($s4)
add $s5, $s5, $s3
li $v0, 4 #Syscall #4 prints string
lb $a0, ($s5) #Loads address of string "inputMsg"
syscall #Prints inputMsg
exit:
li $v0, 10 #syscall #10: exit
syscall #ends program