Full Version : 24 by 16 Bit Division (PIC ASM)
avr >>MATH ROUTINES >>24 by 16 Bit Division (PIC ASM)


Admin3- 04-18-2006
QUOTE
Does anyone have a ready made routine I could use for 24 bit by 16 bit division?


Yes, this is a routine for 24bit / 8bit and it can be easily adapted for
24 by 16 bit.

CODE


;*****************************************************************************
;*****************************************************************************
; 24 Bit / 8 Bit   DIVISION ROUTINE
;
;   ACCb(24BIT) / ACCa(8Bit)  -->  ACCb(24Bit) with remainder ACCc(8BIT)


ACCc           equ $0F  ; To be independent of FSR BANK

ACCb2          equ $18
ACCb1          equ $19
ACCb0          equ $1A
ACCd2          equ $1B
ACCd1          equ $1C
ACCd0          equ $1D
ACCa           equ $1E

Temp           equ $1F


Sub_Divide     movlw 24          ; 24 Bit TO DIVIDE
             movwf Temp
             movf  ACCb2,W     ; D = B
             movwf ACCd2
             movf  ACCb1,W
             movwf ACCd1
             movf  ACCb0,W
             movwf ACCd0
             clrf  ACCb2
             clrf  ACCb1
             clrf  ACCb0
             clrf  ACCc        ; C = 0

dloop          bcf   STATUS,0    ; CARRY = 0
             rlf   ACCd0
             rlf   ACCd1
             rlf   ACCd2       ; Rotate Left D
             rlf   ACCc        ; Rotate Left C
             movf  ACCa,W
             subwf ACCc,W      ; C - A -> W
             btfss STATUS,0    ; Skip if CY=1, i.e. if  C > A
             goto  dloop1
             movf  ACCa,W
             subwf ACCc
             bsf   STATUS,0    ; CARRY = 1

dloop1         rlf   ACCb0
             rlf   ACCb1
             rlf   ACCb2
             decfsz Temp
             goto  dloop
             retlw 0



Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.