Decimal to Hexadecimal Conversion

Page 2/2
1 |

By Prodatron

Paragon (1836)

Prodatron's picture

09-07-2014, 10:57

bore wrote:

If you move the SUB "0" to the test you can get it to stop at any non-decimal character.
Could be useful if the number is in the middle of a longer text but it costs 3 more cycles.

.LOOP
	LD A,(DE)
	SUB "0"
	CP 10
	RET NC

I would do it like this:

.LOOP
	LD A,(DE)
	OR A
	RET Z
	SUB "0"
	CP 10
	CCF
	RET C

So if the routine returns with CF=0, the ASCII string has been converted successfully,
if it returns with CF=1, the ASCII string contains non-numeric chars.

Page 2/2
1 |