A singly linked list, whose first element is pointed at by r0, consists of elements whose head is a 32?bit address pointing to the next element in the list and a variable?length tail. The tail may be of any length greater than four bytes. The last element in the list points to the null address 0. Write a program to search the list for an element whose tail begins with the word in data register r1. On success, set r4 to 0xFF, and r0 should contain the address of the desired record. On failure, load r1 with 0xFFFFFFFF.


The following code implements this search. Note that r1 is initially set with a dummy search item for testing


AREA LinkedList, code, readonly
LDR r1, = 0x12344444 ;look for Item4
ADR r0, List ;r0 points at the linked list
MOV r4,0x00 ;clear success flag in r4
Search LDR r2,[r0] ;REPEAT read pointer field of record
LDR r3,[r0,#4] ;read data field of record
CMP r2,#0 ;test for last item (null pointer)
BEQ Exit_F ;leave on end of list (failure)
CMP r3,r1 ;test for required element
BEQ Exit_S ;exit on success
MOV r0,r2 ;put next item address in r0
B Search ;UNTIL list finished or data found
Exit_S MOV r4,#0xFF ;exit on success (set success flag)
SVC 0x00
Exit_F LDR r1, = 0xFFFFFFFF ;exit point on fail
SVC 0x00
List DCD Item2,0x12341111
Item2 DCD Item3,0x12342222
Item3 DCD Item4,0x12343333
Item4 DCD Item5,0x12344444
Item5 DCD Item6,0x12345555
Item6 DCD Item7,0x12346666
Item7 DCD 0x00, 0x12347777 ;terminator
END

Computer Science & Information Technology

You might also like to view...

To change the style of a chart, you would click the ________ conceptual tab

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which of the following BEST explains the security benefit of a standardized server image?

A. All current security updates for the operating system will have already been applied. B. Mandated security configurations have been made to the operating system. C. Anti-virus software will be installed and current. D. Operating system license use is easier to track.

Computer Science & Information Technology

When you change theme variants, it must affect all slides in the presentation

Indicate whether the statement is true or false

Computer Science & Information Technology

In the accompanying figure, Item 4 points to the ____ for the text defined in the document window.

A. Left Indent marker B. Hanging Indent marker C. First Line Indent marker D. Right Indent marker

Computer Science & Information Technology