Write an ARM assembly language program to determine whether a string of characters with an odd length is a palindrome, for example, mom, under the following constraints

• The string of ASIC?encoded characters is stored in memory.
• At the start of the program, register r1 contains the address of the first character in the string and r2 contains the address of the last character. On exit from the program, register r0 contains a 0 if the string is not a palindrome and 1 if it is.


If the palindrome has an odd number of characters, all we have to do is to examine the end characters and move in until we get to the center; that is,


Setup leftPointer
Setup rightPointer
Clear NotPalindrome
Repeat
IF leftPointer – rightPointer THEN exit on success
Get leftCharacter
Get rightCharacter
IF different then exit on fail
leftPointer = leftPointer + 1
rightPointer = rightPointer + 1
EndRepeat
ExitSucess Set NotPalindrome

AREA Palindrome, code, readonly
ADR r1,TestS ;r1 points to first character
ADR r2,TestE ;r2 contains address of last character + 1
SUB r2,r2,#1 ;now r2 points at the end
MOV r0,#0 ;clear NotPalindrome flag - assume failure
Repeat CMP r1,r2 ;are we there yet?
BEQ ExitS ;if LeftPointer=RightPointer exit success
LDRB r3,[r1] ;get left character
LDRB r4,[r2] ;get right character
CMP r3,r4 ;compare characters
BNE ExitF ;if different then not palindrome
ADD r1,r1,#1 ;move left pointer right
SUB r2,r2,#1 ;move right pointer left
B Repeat ;EndRepeat - go back, test for end
ExitF SVC #0x00 ;exit on fail
ExitS MOV r0,#1 ;exit on success
SVC #0x00
TestS DCB "mom" ;string to test
TestE DCB 0x0D ;dummy end of string
END

Computer Science & Information Technology

You might also like to view...

The ____ calendar item status option shows time with a white bar in Day, Week, Work Week, or Month view.

A. Free B. Tentative C. Out of Office D. Busy

Computer Science & Information Technology

A runnable thread can enter the ______________ state for a specified interval of time.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Identify the letter of the choice that best matches the phrase or definition.

A. A smooth transition from shadows to midtones to highlights B. The relationship between the highlights and the shadows C. A visual reference of every pixel in the image or selection D. Identifying pixel information in the Info panel E. The additive primary colors

Computer Science & Information Technology

________ are stored sets of instructions that automate common tasks

A) Macros B) Templates C) Adds-Ins D) ActiveX Controls

Computer Science & Information Technology