Dang! I forgot the brackets on the previous post. ;************************************************ James has asked me to post this working version of this 16-bit-binary-to-5- digit BCD routine, which appears here in "modern" notation. (Some will recall my previous questions regarding the use of the $ for 0xnn, etc.) Anyway, per his request, here it is. It works very well, and is very fast. I want to make clear that I only swiped it from the archives, and with the help of other piclisters, cleaned it up a bit to make it work in my current application. Apparently it was originally written by John Payson. Regards, Foster ;**************************************************************** bin2bcd nop ;Takes hex number in NumH:NumL ;Returns decimal in ;TenK:Thou:Hund:Tens:Ones ;written by John Payson ;requires the following memory variables: ;NumH ;NumL ;TenK ;Thou ;Hund ;Tens ;Ones swapf NumH,w iorlw b'11110000' movwf Thou addwf Thou,f addlw .226 movwf Hund addlw .50 movwf Ones movfw NumH andlw b'00001111' addwf Hund,f addwf Hund,f addwf Ones,f addlw .233 movwf Tens addwf Tens,f addwf Tens,f swapf NumL,w andlw b'00001111' addwf Tens,f addwf Ones,f rlf Tens,f rlf Ones,f comf Ones,f rlf Ones,f movfw NumL andlw b'00001111' addwf Ones,f rlf Thou,f movlw 7 movwf TenK ; At this point, the original # == 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 normalized, ; but this can all be done with simple byte arithmetic. movlw .10 Lb1: addwf Ones,f decf Tens,f skpc goto Lb1 Lb2: addwf Tens,f decf Hund,f skpc goto Lb2 Lb3: addwf Hund,f decf Thou,f skpc goto Lb3 Lb4: addwf Thou,f decf TenK,f skpc goto Lb4 RETURN ;*************************************************************** -----Original Message----- From: James Newton [mailto:jamesnewton@piclist.com] Sent: Monday, September 25, 2000 9:41 AM To: foster@ADASTRAN.COM Subject: RE: [PIC]: Could someone please explain this asm notation? If you do get that converted to "modern" notation and are able to make use of it, please consider posting an update to the list with the working version so that the code will be more useful to others. I'll update the web page and credit you for the help. Thanks. --- James Newton (PICList Admin #3) mailto:jamesnewton@piclist.com 1-619-652-0593 PIC/PICList FAQ: http://www.piclist.com or .org -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of adastra Sent: Saturday, September 23, 2000 14:08 To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: Could someone please explain this asm notation? 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:) ;********************************************************** previously posted code snipped -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu