Advanced
Binary to Decimal
Convert a binary string to its decimal value.
A null-terminated string at x5000 contains only '0' and '1' characters representing a binary number (e.g., "1101"). Convert this to its decimal value and store the result at x6000. The binary number will be at most 8 bits (value 0-255).
Requirements:
• The string contains only ASCII '0' (x30) and '1' (x31) characters
• Convert the binary representation to its integer value
• Store the result at x6000
Algorithm: Process left to right. For each digit:
result = result * 2 + digit
Example: "1101"
• Start: result = 0
• Read '1': result = 0 * 2 + 1 = 1
• Read '1': result = 1 * 2 + 1 = 3
• Read '0': result = 3 * 2 + 0 = 6
• Read '1': result = 6 * 2 + 1 = 13
Key insight: Multiplication by 2 is just ADD R0, R0, R0 (adding a number to itself).
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