Bob Segrest wrote: >I am working on a micro controller project using a PIC16C73... Due to a >change in end user requirements I need to output a two byte binary counter >as a signed decimal number in the range of -32767 to +32767. Bob, Here is a routine posted by John Payson that does tht job. First, test the sign of the number and save the sign. Convert to positive, if negative by complementing and adding 1. Then use: (NB: 49 program memory locations. Executes in 153 to 198 clock cycles (worst case I could find) BF) cblock NumH NumL TenK Thou Hund Tens Ones endc ; Takes number in NumH:NumL ; Returns decimal in TenK:Thou:Hund:Tens:Ones convert: swapf NumH,w iorlw h'f0' movwf Thou addwf Thou,f addlw h'E2' movwf Hund addlw h'32' movwf Ones movf NumH,w andlw h'0F' addwf Hund,f addwf Hund,f addwf Ones,f addlw h'E9' movwf Tens addwf Tens,f addwf Tens,f swapf NumL,w andlw h'0F' addwf Tens,f addwf Ones,f rlf Tens,f rlf Ones,f comf Ones,f rlf Ones,f movf NumL,w andlw h'0F' addwf Ones,f rlf Thou,f movlw h'07' movwf TenK ; At this point, the original number is ; equal to TenK*10000+Thou*1000+Hund*100+Tens*10+Ones ; if those entities are regarded as two's compliment ; binary. To be precise, all of them are negative ; except TenK. Now the number needs to be normal- ; ized, but this can all be done with simple byte ; arithmetic. movlw h'0A' ; Ten Lb1: addwf Ones,f decf Tens,f btfss 3,0 goto Lb1 Lb2: addwf Tens,f decf Hund,f btfss 3,0 goto Lb2 Lb3: addwf Hund,f decf Thou,f btfss 3,0 goto Lb3 Lb4: addwf Thou,f decf TenK,f btfss 3,0 goto Lb4 retlw 0 -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com