Question: Write procedure in MIPS using MARS simulator (STOP POSTING SPAM!!) Write a MIPS procedure called findx using the given .asm file which finds the first

Write procedure in MIPS using MARS simulator (STOP POSTING SPAM!!)

Write a MIPS procedure called findx using the given .asm file which finds the first occurrence of the letter x in an area of memory (array). The procedure receives three arguments in $a1, $a2, and $a3, where $a1 is the starting memory address of a null-terminated ASCII string, $a2 has the starting index (0) and $a3 is the x character. The findx procedure will locate the first x character in the string and return the position where it was found in register $v1. If there are no xes in the string, findx should return -1 in register $v1. Your program should print the index returned by findx using a syscall. Make sure to write plenty of comments so that your code is as easy to understand. Hint: StrCopy

________________________________________________________________

findx.asm

la $a0, prompt # Load address of prompt text into argument

li $v0, 4 # Display Prompt

syscall

li $v0, 9 # Create space for string

li $a0, 100 # 100 bytes

syscall

addi $a0, $v0, 0 # Get address of heap space allocated

li $v0, 8 # Read string

li $a1, 100 # accept 100 bytes

syscall

addi $a1, $a0, 0 # Transfer string address to correct argument

li $a2, 0 # Set starting index to 0

li $a3, 'x' # Set target character to 'x'

findx: # POST CODE HERE #

Found:

addi $v1, $t1, 0 # Set v1

la $a0, result # Load address of result text into argument

li $v0, 4 # Display Result text

syscall

addi $a0, $v1, 0 # Load result index into argument

li $v0, 1 # Display Integer (index)

syscall

j Exit # Exit

NotFound:

la $a0, notfnd # Load address of notfnd text into argument

li $v0, 4 # Display Result text

syscall

Exit:

.data

prompt: .asciiz "Enter a test string: "

result: .asciiz "Found first 'x' at: "

notfnd: .asciiz "No 'x' found."

____________________________________________________

Here is my attempt at findx (no good):

add $t1, $s0, $a1 # $a1 address put into $t1

lb $t1, 0($t1)

beqz $t1, Found # if $t1 = 0, go to Found

bnez $t1, NotFound # if $t1 != 0, go to NotFound

addi $s0, $s0, 1 # increment

j findx # next iteration of loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!