Trying to traverse a .word “Table” in MIPS Assembl

2019-08-20 12:21发布

问题:

I seem to be having a issue understanding part of the project my teacher assigned.

So the basic Idea is that I have a .word "table", Full of IP addresses. I need to be able to traverse the table and compare the different values and match the numbers up with user input. I also need to account for any size table, not just the table that he gave us.
I first tested out trying to get through the table first, because I have never worked with the .word before. I figured out how to load the table, and how to use the offsets for one line, the issue is when I try to get to the next line. I thought that I was supposed to use:

addi $a0, 20  
I have also tried the addu and add instructions.

This was to get to the next line, however I get to an Exception 4, which is a data fetch error. This happens after I try to load a new word like:

lw $s0, ($a0)

I am not really sure what to do from here, I know that $a0 is getting incremented outside of where the table is, I am just unsure how to fix it or what the actual code should be. Here is what I am using to test with.

.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

Sorry this became more lengthy than it probably should have been, I just wanted to make sure it was understood what was happening. Thanks for the help.

Also, I have tried using the debugger and it hasn't helped me figure out the issue.

标签: assembly mips