2

I am new to assembly language, and I have a project that I am struggling with. I don't want code; I just want to make sure I am thinking about the problem correctly so I don't drive myself crazy implementing a bad or down-right incorrect approach.

The problem can be summarized as such:

We have an array of strings in memory as such:

.data
animals:    .asciiz    "bear", "tiger", "gorilla", "horse", "dog"

We want to take a user's input string and store it into str:

.data
animals:    .asciiz    "bear", "tiger", "gorilla", "horse", "dog"
str: .space  64    #user input stored here

Then we want to see if the user has entered something that exists in the existing arry of strings in memory. So if the user were to enter, "horse" we would return "Found!" and if they were to enter "garage" we would return "Not found."

To actually do this, I am thinking that I would need to compare every character (each byte) of the input string with the corresponding character (byte) of each string in the array.

I have two main questions: is this a good approach/correct thinking about the problem? and how could I go about making the program recognize when has hit the end of one string in the array and started a new one?

Thank you so much for any responses. I'm sorry if any of this is unclear or a bad question. I am having a hard time wrapping my head around assembly.

1 Answer 1

2

You need to know where each of the animals strings start in memory. Try this:

.data
animals:    
a0: .asciiz    "bear"
a1: .asciiz    "tiger"
a2: .asciiz    "gorilla"
a3: .asciiz    "horse"
a4: .asciiz    "dog"

# addrs is a list of the starting addresses for each of the strings
addrs: 
  .word a0
  .word a1
  .word a2
  .word a3
  .word a4
  .word 0

Now you can write code to loop through each of the addresses starting at addrs and comparing the user's string with the reference strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.