I'm designing a calculator on atmega328p using assembly language, after performing the calculation I need to separate the result into digits to display them on LED matrix. Till now I wrote a code that does that with an 8-bit number (one register) and it's working correctly. However, when I start using two register for the high and low part of the number I'm not able to come up with a code that does the same.
the code for working with 8-bit number is attached below:
ldi r19, 0
HUNDS:
cpi resL, 100 ;compare low part of the result register with 100
brlo TENS
subi resL, 100
inc r19
rjmp HUNDS
TENS:
st x+, r19 ;store hundreds counter in buffer for screen display (will be displayed on first screen block)
ldi r19, 0 ;reset counter for tens
TENS_Test:
cpi resL, 10
brlo UNITS
subi resL ,10
inc r19
rjmp TENS_Test
UNITS:
st x+, r19 ; store tens counter
st x+, resL ; store units digit