Advanced

Reverse String In Place

Reverse a null-terminated string in memory.

A null-terminated string is stored at memory location x5000. Write a program to reverse the string in place (modify the original memory). For example, "HELLO" becomes "OLLEH".

Requirements:
• Reverse the string stored at x5000 in place

• The null terminator should remain at the end

• Store the length of the string at x6000

Algorithm:
1. First find the end of the string (scan for null terminator)
2. Use two pointers: one at start, one at end
3. Swap characters at those positions
4. Move pointers toward each other
5. Stop when they meet or cross

Swapping two values:

LDR R2, R1, #0    ; R2 = value at pointer 1
LDR R3, R4, #0    ; R3 = value at pointer 2
STR R3, R1, #0    ; store pointer 2's value at pointer 1
STR R2, R4, #0    ; store pointer 1's value at pointer 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33