piclist 2017\09\07\091719a >
www.piclist.com/techref/microchip/math/index.htm?key=division
BY : David C Brown email (remove spam text)

Perhaps I have been selling myself short !  Whist I thank you for your
suggestions at the risk of sounding sarcastic which is not my intent, there
is nothing there that I couldn't get from my 1967 university textbook..  Or
from experienced engineers in my first job at International  Computers Ltd
in 1969.

The basic non restoring algorithm must have been developed by Turing or
Wilkes or one of there contemporaries back in the fifties.   For interest,
or not, This my take on it. - 55 memories, 2 working registers,  worst case

..;=============================================================================;
; This Routine divides DIVIDEND BY DIVISOR for numbers less than 1. That is
;
; numbers with an implied binary point aat the extreme left.   The divisor
;
; must be greater than the dividend so thaat the quotient remains less than
1 ;
; ENTRY: Dividend in REGA.  Divisor in REGB
;
;  EXIT: Quotient in REGAX,REGA  W is 0
;
;        (IF Dividend > Divisor W is -1  and REGAX,REGA = REGA -REGB)
;
;  USES: REGQ, DCNT
;
;=============================================================================;

DIV88 MOVLF 8,DCNT
CLRF REGQ
CLRF REGAX

SUB21 REGAX,REGA,REGB ; REGA = REGA - REGB
BTFSC _C ; initial subtraction should be negative
RETLW -1 ; if Divisor is  greater than dividend

D880 RLF REGA ; REGA = 2* REGA + carry from previous operation
RLF REGAX ; so that carry is in A0

BTFSC REGA,0 ; skip if negative
GOTO D881

RLF REGQ ; Negative result
BCF REGQ,0 ; zero shifted into quotient
BCF REGA,0 ; clear saved carry from dividend
ADD21 REGAX,REGA,REGB ; REGA = REGAA + REGB
GOTO D882

D881 RLF REGQ ; Positive result
BSF REGQ,0 ; one shifted in
BCF REGA,0 ; clear saved carry
SUB21 REGAX,REGA,REGB ; REGA = REGAA - REGB

D882 DECFSZ DCNT
GOTO D880

RLF REGQ,W
MOVWF REGAX
BTFSC REGAX,0
RETLW 0
RETLW 0

__________________________________________
David C Brown
Whaley Bridge
High Peak                           Phone: 01663 733236
Derbyshire                eMail: dcb.homegmail.com
SK23 7ND          web: http://www.bings-knowle.co.uk/dcb
<http://www.jb.man.ac.uk/~dcb>

*Sent from my etch-a-sketch*

On 6 September 2017 at 21:39, Walter Banks <walterbytecraft.com> wrote:

{Quote hidden}

-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive