;****************************************************************************** ; Subroutines to do Decimal to Hexidecimal and Decimal to Binary Convertion ;****************************************************************************** dectohex: ldi ZL,low(answer) ;Z points to answer ldi ZH,high(answer) ldi temp,azero ;temp = ascii 0 top: cpi op2hi,16 ;is op2 less than 16? brlo bot ;if yes, goto bot subi op2hi,16 ;op2 = op2 - 16 cpi temp,0x39 ;compare temp to ascii 9 breq sktp ;if equal, goto sktp inc temp ;inc temp rjmp top ;goto top sktp: ldi temp,'A' ;temp = 'A' rjmp top ;goto top bot: st Z+,temp ;store temp and inc Z cpi op2hi,10 ;compare op2 to 10 brge skbt ;if greater than or equal to goto skbt ldi temp,azero ;temp = ascii zero bot1: add temp,op2hi ;temp = temp + op2 st Z+,temp ;store temp and inc Z ldi temp,0x00 ;temp = 0 st Z+,temp ;store temp and inc Z ret ;return skbt: ldi temp,'A' ;temp = 'A' subi op2hi,10 ;op2 = op2 - 10 rjmp bot1 ;goto bot1 dectobin: ldi ZL,low(answer) ;Z points to answer ldi ZH,high(answer) ldi temp,azero ;temp = ascii 0 sbrc op2hi,7 ;skip next if bit 7 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,6 ;skip next if bit 6 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,5 ;skip next if bit 5 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,4 ;skip next if bit 4 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,3 ;skip next if bit 3 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,2 ;skip next if bit 2 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,1 ;skip next if bit 1 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,azero ;temp = ascii 0 sbrc op2hi,0 ;skip next if bit 0 is clear inc temp ;inc temp st Z+,temp ;store temp, inc Z ldi temp,0x00 ;temp = 0 st Z+,temp ;store temp, inc Z ret ;return