I need to convert 16 bit binary to 4 BCD digits. I searched the archives and thought I had found just the right thing, so I more-or-less just pasted it into my 16C877 code. However, MPASM gives error messages on the lines with the ds and $ directives. I can't find any references to the $ (except where it returns the PCL) in the MPASM user's guide. Could someone please explain what I need to know in order to modify this code to produce the desired result? Thanks very much, Foster (CODE FROM ARCHIVES FOLLOWS:) ;********************************************************** ; Binary-to-BCD. Written by John Payson. ; ; Enter with 16-bit binary number in NumH:NumL. ; Exits with BCD equivalent in TenK:Thou:Hund:Tens:Ones. NumH: ds 1 NumL: ds 1 TenK: ds 1 Thou: ds 1 Hund: ds 1 Tens: ds 1 Ones: ds 1 Convert: ; Takes number in NumH:NumL ; Returns decimal in ; TenK:Thou:Hund:Tens:Ones swapf NumH,w andlw 0x0f andlw 0xf0 movwf Thou addwf Thou,f addlw $E2 movwf Hund addlw $32 movwf Ones movf NumH,w andlw $0F addwf Hund,f addwf Hund,f addwf Ones,f addlw $E9 movwf Tens addwf Tens,f addwf Tens,f swapf NumL,w andlw $0F addwf Tens,f addwf Ones,f rlf Tens,f rlf Ones,f comf Ones,f rlf Ones,f movf NumL,w andlw $0F addwf Ones,f rlf Thou,f movlw $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 $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 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu