| QUOTE |
| I can save 600 bytes in a lookup table if I can figure out a good way to divide a 16 bit number by 10. |
| CODE |
N_hi equ 0x20 N_lo equ 0x21 count equ 0x22 R_hi equ 0x23 R_lo equ 0x24 ;---------------------------------- ;divby10 ; Divides the unsigned integer N_hi:N_lo by the constant 10. ; ;Input ; N_lo - Low byte of the 16 bit dividend ; N_hi - High " " ;Output ; R_lo - Low byte of the result ; R_hi - High " " ; ; 14 words ; 149 cycles divby10_ver3 CLRF R_lo ;Only need to clear R_lo. R_hi is cleared by shifting(below) MOVLW 13 MOVWF count ; v3_1 MOVLW 0xa0 ;If the high byte is greater than or equal to 0xa0, SUBWF N_hi,W ;then this subtraction causes no borrow (i.e. C=1) SKPNC MOVWF N_hi ;Replace N_hi with N_hi - 0xa0 if RLF R_lo,F ;Shift result left one bit and RLF R_hi,F ; pick up the carry bit in the process. RLF N_lo,F ;Adjust N for the next iteration. RLF N_hi,F DECFSZ count,F goto v3_1 RETURN |