Advanced

Remove Spaces

Remove all spaces from a string in place.

A null-terminated string is stored at x5000. Write a program to remove all spaces from the string, modifying it in place. Store the new length (after removing spaces) at x6000.

Example: "H E L L O" becomes "HELLO" and store 5 at x6000.

Requirements:
• Remove all space characters (ASCII x20 / decimal 32) from the string

• Modify the string in place at x5000

• Write a null terminator after the last non-space character

• Store the new length at x6000

Algorithm: Two-pointer approach
• Read pointer: scans through original string

• Write pointer: tracks where to write next non-space character

• For each character:

- If it's a space, skip it (advance read pointer only)
- If it's not a space, write it at the write pointer position, advance both
• At the end, write null terminator at write pointer position

• Length = write pointer - start address

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