在我老师分配的项目的一部分中,我似乎遇到了问题。
因此,基本思路是,我有一个充满IP地址的.word“表”。我需要能够遍历表格并比较不同的值,并使数字与用户输入相匹配。我还需要考虑任何尺寸的表,而不仅仅是他给我们的表。
我首先进行了测试,尝试首先通过该表,因为我以前从未使用过.word。我弄清楚了如何加载表格,以及如何在一行中使用偏移量,问题是当我尝试到达下一行时。我以为我应该使用:
addi $a0, 20
I have also tried the addu and add instructions.
这是到下一行的内容,但是我到了异常4,这是数据获取错误。这种情况发生在我尝试加载新词后:
lw $s0, ($a0)
我不确定从这里开始该怎么做,我知道$ a0在表所在位置之外逐渐增加,我不确定如何修复它或实际代码应该是什么。这是我用来测试的东西。
.data
MESSAGE1: .asciiz "Enter an IP address\n"
MESSAGE2: .asciiz "First: "
MESSAGE3: .asciiz "Second: "
MESSAGE4: .asciiz "Third: "
MESSAGE5: .asciiz "Fourth: "
MESSAGE6: .asciiz "The IP address you enterd: "
MESSAGE7: .asciiz "."
MESSAGE8: .asciiz "\nClass A address\n"
MESSAGE9: .asciiz "\nClass B address\n"
MESSAGE10: .asciiz "\nClass C address\n"
MESSAGE11: .asciiz "\nClass D address\n"
MESSAGE12: .asciiz "\nInvalid domain class\n"
MESSAGE13: .asciiz "\nProgram successfully completed . . .\n"
MESSAGE14: .asciiz "\n"
MESSAGE15: .asciiz "Matching domain found at: "
MESSAGE16: .asciiz "Matching domain was NOT found . . . \n"
ERROROVER: .asciiz "The entered number is larger than 255.\n"
ERRORUNDER: .asciiz "The entered number is smaller than 0.\n"
ERROR: .asciiz "Invalid Number detected make sure the number entered is
between 0 and 255."
IP_ROUTING_TABLE_SIZE:
.word 10
IP_ROUTING_TABLE:
# line #, x.x.x.x -------------------------------------
.word 0, 146, 92, 255, 255 # 146.92.255.255
.word 1, 147, 163, 255, 255 # 147.163.255.255
.word 2, 201, 88, 88, 90 # 201.88.88.90
.word 3, 182, 151, 44, 56 # 182.151.44.56
.word 4, 24, 125, 100, 100 # 24.125.100.100
.word 5, 146, 163, 140, 80 # 146.163.170.80
.word 6, 146, 163, 147, 80 # 146.163.147.80
.word 10, 201, 88, 102, 80 # 201.88.102.1
.word 11, 148, 163, 170, 80 # 146.163.170.80
.word 12, 193, 77, 77, 10 # 193.77.77.10
.text
.globl main
main:
la $a0, IP_ROUTING_TABLE
lw $s0, ($a0)
lw $s1 4($a0)
lw $s2, 8($a0)
lw $s3, 12($a0)
lw $s4, 16($a0)
li $v0, 1
move $a0, $s0
syscall
li $v0, 4
la $a0, MESSAGE14
syscall
li $v0, 1
move $a0, $s1
syscall
li $v0, 4
la $a0, MESSAGE14
syscall
li $v0, 1
move $a0, $s2
syscall
li $v0, 4
la $a0, MESSAGE14
syscall
li $v0, 1
move $a0, $s3
syscall
li $v0, 4
la $a0, MESSAGE14
syscall
li $v0, 1
move $a0, $s4
syscall
li $v0, 4
la $a0, MESSAGE14
syscall
addi $a0, 20
lw $s0, ($a0) #problem is here
li $v0, 1
move $a0, $s0
syscall
P_EXIT: jr $31
抱歉,这变得比原本应该更长的时间,我只是想确保它能理解正在发生的事情。感谢您的帮助。
此外,我尝试使用调试器,但并没有帮助我解决问题。