Question: need help with assembky code, why does it return true for sinlge palindrome characters but not for things like 'dad' or 'madam': . section .
need help with assembky code, why does it return true for sinlge palindrome characters but not for things like 'dad' or 'madam': section data
inputprompt: asciz "Input a string:
inputspec: asciz s
palindromespec: asciz "String is a palindrome TF: c
section text
global main
main:
Print prompt for input
ldr xinputprompt
bl printf
Allocate bytes on the stack for input
sub sp sp #
mov x sp Buffer points to the top of the stack
Read the input string using scanf
ldr xinputspec
bl scanf
Call strlen to calculate string length
mov x sp Buffer address now on the stack
bl strlen
sub x x # Set x to length last valid character index
Call the recursive palindrome check
mov x sp Buffer string address
mov x # Initial start index
bl checkpalindrome
Check the result
cmp x #
bne notpalindrome
mov wT
b printresult
notpalindrome:
mov wF
printresult:
ldr xpalindromespec
bl printf
b exit
exit:
add sp sp # Restore the stack by freeing allocated memory
mov x
mov x
svc
Recursive palindrome checking function
checkpalindrome:
Allocate bytes of stack space
sub sp sp #
Save return address and arguments on the stack
stp x xsp # Save return address and xstart index
stp x xsp # Save xstring pointer and xend index
Base case: start index end index weve checked all characters
cmp x x
bge palindrometrue
Load characters at the start x and end x of the string
ldrb wx x
ldrb wx x
cmp w w
bne palindromefalse If characters don't match, return false
Recursive case: move start forward, end backward
add x x #
sub x x #
Recursive call
bl checkpalindrome
Restore return address and arguments
ldp x xsp #
ldp x xsp #
Unwind the stack
add sp sp #
ret
palindrometrue:
Restore stack and return true
add sp sp #
mov x #
ret
palindromefalse:
Restore stack and return false
add sp sp #
mov x #
ret
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
