Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In ARM Assembly I need to finish the palindrome function. The function must use a recursive algorithm. The string contains only letters, no digits, spaces,
In ARM Assembly I need to finish the palindrome function.
The function must use a recursive algorithm. The string contains only letters, no digits, spaces, or punctuation
.equ inputMode, 0 @ Set file mode to input .equ outputMode, 1 @ Set file mode to output .equ appendMode, 2 @ Set file mode to append .equ stdout, 1 @ Set output target to be Stdout .equ False, 0 .equ True, 1 @------------------------------------------------------- @ Main Program @ Test the first string MOV R0, #stdout LDR R1, =TestStringStr SWI SWI_PrStr LDR R1, =Pal1 SWI SWI_PrStr BL PrintLF MOV R0, #stdout LDR R1, =PalindromeStr SWI SWI_PrStr LDR R1, =Pal1 BL strlen MOV R2, R0 BL Palindrome BL PrintTrueFalse BL PrintLF @ Test the second string MOV R0, #stdout LDR R1, =TestStringStr SWI SWI_PrStr LDR R1, =Pal2 SWI SWI_PrStr BL PrintLF MOV R0, #stdout LDR R1, =PalindromeStr SWI SWI_PrStr LDR R1, =Pal2 BL strlen MOV R2, R0 BL Palindrome BL PrintTrueFalse BL PrintLF SWI SWI_Exit @------------------------------------------------------- PrintLF: /* ------------------------------------------------------- Prints the line feed character ( ) ------------------------------------------------------- Uses: R0 - set to ' ' (SWI_PrChr automatically prints to stdout) ------------------------------------------------------- */ STMFD SP!, {R0, LR} MOV R0, #' ' @ Define the line feed character SWI SWI_PrChr @ Print the character to Stdout LDMFD SP!, {R0, PC} @------------------------------------------------------- PrintTrueFalse: /* ------------------------------------------------------- Prints "True" or "False" to stdout as appropriate ------------------------------------------------------- Uses: R0 - input parameter, then set to stdout R1 - set to address of "True" ------------------------------------------------------- */ STMFD SP!, {R0-R1, LR} CMP R0, #0 @ Is R0 False? LDREQ R1, =FalseStr @ load "False" message LDRNE R1, =TrueStr @ load "True" message MOV R0, #stdout SWI SWI_PrStr @ Print the string to Stdout LDMFD SP!, {R0-R1, PC} TrueStr: .asciz "True" FalseStr: .asciz "False" @------------------------------------------------------- strlen: /* ------------------------------------------------------- Determines the length of a string. ------------------------------------------------------- Uses: R0 - returned length R1 - address of string R2 - current character ------------------------------------------------------- */ STMFD SP!, {R1-R2, LR} MOV R0, #0 @ Initialize length strlenLoop: LDRB R2, [R1], #1 @ Read address with post-increment (R2 = *R1, R1 += 1) CMP R2, #0 @ Compare character with null ADDNE R0, R0, #1 BNE strlenLoop @ If not at end, continue LDMFD SP!, {R1-R2, PC} @------------------------------------------------------- Palindrome: /* ------------------------------------------------------- Determines if a string is a palindrome (Recursive) ------------------------------------------------------- Uses: R0 - returns True if palindrome, False otherwise R1 - address of string R2 - length of string @ your further comments here ------------------------------------------------------- */ YOUR CODE HERE @------------------------------------------------------- TestStringStr: .asciz "Test String: " PalindromeStr: .asciz "Palindrome: " Pal1: .asciz "racecar" Pal2: .asciz "notapalindrome" .end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started