I am working with ARM Assembly. I want to reverse a string, so if you pass the string "abcdefg", it will change the string to "gfedcba".
Essentially, this assembly code should be an implementation of:
void reversing(char *strn);
My line of thinking is that I have to keep a pointer to each string end. Then I would simply increment one and then decrement the other.
reversing:
stmfd sp!,{r4-r8,lr} @ Push to stack
@ Solution here
ldmfd sp!,{r4-r8,lr} @ Pop from stack
bx lr @ return
I am not sure the actual method to implement this into assembly code, so any suggestions would be great.
Attempted Solution:
reversing:
stmfd sp!,{r4-r8,lr} @ push to stack
mov r5, #0 @ r5 = 0, beginning
b my_strlen @ get r4 = strlen
next:
loop:
ldrb r6, [r0] @ Get char string
@ Not too sure about this part.
strb r7, [r5]
add r5, #1
sub r4, #1
cmp r4, r5
bhi loop
end_reverse:
ldmfd sp!,{r4-r8,lr}
bx lr @ return
@
@ strlen function
@
my_strlen:
@ Register usage:
@ r0: string pointer
@ r4: counter
mov r4,#0 @ zero the counter
counter:
ldrb r2,[r0] @ Get character string
movs r2,r2 @ Set flags
beq strlen_done
add r4,#1 @ Count the letter
add r0,#1 @ Advance to the next character
b counter @ Loop back
strlen_done:
b next