divide movlw 32 ; 32-bit divide by 16-bit
movwf bitcnt
clrf remdrH ; Clear remainder
clrf remdrL
dvloop clrc ; Set quotient bit to 0
; Shift left dividend and quotient
rlf divid0 ; lsb
rlf divid1
rlf divid2
rlf divid3 ; lsb into carry
rlf remdrL ; and then into partial remainder
rlf remdrH
skpnc ; Check for overflow
goto subd
movfw divisH ; Compare partial remainder and divisor
subwf remdrH,w
skpz
goto testgt ; Not equal so test if remdrH is greater
movfw divisL ; High bytes are equal, compare low bytes
subwf remdrL,w
testgt skpc ; Carry set if remdr >= divis
goto remrlt
subd movfw divisL ; Subtract divisor from partial remainder
subwf remdrL
skpc ; Test for borrow
decf remdrH ; Subtract borrow
movfw divisH
subwf remdrH
bsf divid0,0 ; Set quotient bit to 1
; Quotient replaces dividend which is lost
remrlt decfsz bitcnt
goto dvloop
return
Comments:
Questions:
| file: /Techref/microchip/math/div/32by16ph.htm, 2KB, , updated: 2020/2/12 20:49, local time: 2025/10/27 06:29,
owner: JMN-EFP-786,
216.73.216.188,10-3-157-36:LOG IN
|
| ©2025 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/techref/microchip/math/div/32by16ph.htm"> 32 bits by 16 by Peter Hemsley</A> |
| Did you find what you needed? |
Welcome to ecomorder.com! |
|
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.