Hey, I'm not sure if this is the right place to post this but anyway.

Does anyone know of an algorithm which can be used to print out decimal values from a register using machine code.

Basically, the machine code debugger I am using has an instruction that will output a character corresponding to value of a byte. At the moment I am doing the following:

$1 - stores number to be output

$2 - counter

$3 - unit

$4 - tens

basically I increment $2 and $3 until $2 is equal to $1. Meanwhile, if $3 becomes equal to 10 (in decimal) I reset $3 to 0 and increment $4 by one. I then take the number of tens and unit and add 48 to convert them into the correct ascii character for writing out to the screen.

Obviously, if the number is greater than two digits my algorithm doesn't work. Sure, I could implement a hundredth counter, thousandth counter etc but the code becomes poor and messy.

Thanks,