QuestionQuestion

In this lab, you are given a string in memory, and you must search through the string to find the ASCII characters “HELP” in order, though not necessarily sequentially. The address of the first time each character is found should be stored in registers r4, r5, r6, and r7 (the first ‘H’ instance in r4, the first ‘E’ instance in r5, ect). If and only if all the letters are found in order, the string is considered valid, and the address of the first instance of ‘H’ should also be stored in r0. If the letters are not found in order, 0x00 should be stored in r0 instead. To make life easier for you, the string will be null terminated (will end with a 0 character). The program will terminate when the “P” is found or when the null terminator is reached, whichever comes first.

Example: If the searched string started at 0x800 and read: “HQEQLQPQ”, 0x800 should be stored in r0 at the end of the program. However, if the string read “PLEHEL”, nothing will be stored in r0.

Code Given:

For this lab, you are given an outline (that you may choose not to use) of the entire program. The program utilizes branches, which you should be familiar enough with to utilize the given code:

AREA Lab4, CODE, ALIGN=2
ENTRY

FindH

BEQ FindE ;if ‘H’ is found, branch to the E finder

BNE FindH ;if 0 terminator not found, keep searching for H
BEQ STOP ;if 0 terminator found, branch to stop
FindE

BEQ FindL ;if ‘E’ is found, branch to the L finder

BNE FindE ;if 0 terminator not found, keep searching for E
BEQ STOP ;if 0 terminator found, branch to stop
FindL

BEQ FindP ;if ‘L’ is found, branch to the P finder

BNE FindL ;if 0 terminator not found, keep searching for L
BEQ STOP ;if 0 terminator found, branch to stop

FindP

BEQ STOP ;if ‘P’ is found, branch to the stop

BNE FindP ;if 0 terminator not found, keep searching for P
BEQ STOP ;if 0 terminator found, branch to stop

STOP B STOP

AREA asm_data, DATA, READONLY
TEST_DATA
DCB "psdfnOLHHNOHDP[[HELkhjxvcphelHELLpppHELP",0
END

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

AREA Lab4, CODE, ALIGN=2
ENTRY
EXPORT __main
__main

MOV R0, #0 ;initialize r0 to 0
LDR R1, =TEST_DATA ;load address of the first character to R1

FindH
LDRB R2, [R1] ;load next character to R2
CMP R2, #0x48 ;check if the character is 'H' (ascii code 0x48)
BEQ StoreH ;if ‘H’ is found, store its address and continue to the E finder
CMP R2, #0 ;check if the character is null (0 terminator)
BEQ STOP ;if 0 terminator found, branch to stop
ADD R1, R1, #1 ;else, increment address to point to the next character
B FindH ;and keep searching for H

StoreH
MOV R4, R1 ;store address of first 'H' to R4...

By purchasing this solution you'll be able to access the following files:
Solution.s.

$10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats