Ouch! It seems that I accidentally posted my previous message twice to the list, and it wasn't even the correct code. Thing is, I generally use a lot of macros in my code to make it more readable and less typing, i.e. STR rather than MOVWF. These macros make PIC assembly look more like other processors, but it of course means that *you* can't assemble the code without problems. So once more, here's my 32-bit binary to BCD code, which by the way seems to be both shorter and faster than most of the *16-bit* solutions I've seen. 40 instructions, two temporary registers needed and 2785 cycles. If enough people ask, I'll write a 16-bit version as well, which should run in about 1100 cycles. Anyone care to try to do better than that? ; +---------------------------------------------------------------------+ ; | | ; | Binary to BCD conversion. | ; | | ; +---------------------------------------------------------------------+ ; ; In: reg3,reg2,reg1,reg0 : 32-bit integer ; Act: Converts a 32 bit binary number to packed BCD ; Out: dig4,dig3,dig2,dig1,dig0 : BCD result (must be in increasing address order) ; Regs: Temp, Count ; Note: Uses one stack level internally. ; Execution time is 2785 cycles (1948 cycles using in-line code for B2B_Adjust). 0000: 3020 bin2bcd movlw 32 0001: 00A9 movwf Count 0002: 01A0 clrf dig4 0003: 01A1 clrf dig3 0004: 01A2 clrf dig2 0005: 01A3 clrf dig1 0006: 01A4 clrf dig0 0007: 1003 bcf status,status_carry 0008: 2810 goto B2B_Enter 0009: 3024 B2B_Loop movlw dig0 000A: 0084 movwf fsr 000B: 201C call B2B_Adjust 000C: 201C call B2B_Adjust 000D: 201C call B2B_Adjust 000E: 201C call B2B_Adjust 000F: 201C call B2B_Adjust 0010: 0DA5 B2B_Enter rlf reg0,f 0011: 0DA6 rlf reg1,f 0012: 0DA7 rlf reg2,f 0013: 0DA8 rlf reg3,f 0014: 0DA4 rlf dig0,f 0015: 0DA3 rlf dig1,f 0016: 0DA2 rlf dig2,f 0017: 0DA1 rlf dig3,f 0018: 0DA0 rlf dig4,f 0019: 0BA9 decfsz Count,f 001A: 2809 goto B2B_Loop 001B: 0008 return 001C: 3003 B2B_Adjust movlw 3 001D: 0700 addwf ind,w 001E: 00AA movwf Temp 001F: 19AA btfsc Temp,3 0020: 0080 movwf ind 0021: 3030 movlw 0x30 0022: 0700 addwf ind,w 0023: 00AA movwf Temp 0024: 1BAA btfsc Temp,7 0025: 0080 movwf ind 0026: 0384 decf fsr,f 0027: 0008 return Cheers, Frank ------------------------------------------------------------------------ Frank A. Vorstenbosch Phone: +44-181-941 7899 Electronics & Software Engineer Mobile: +44-976-430 569 Eidos Technologies Ltd., Hampton, Middx Fax: +44-181-941 7895