piclist 2017\09\07\091719a >
Thread: Division routines.
www.piclist.com/techref/microchip/math/index.htm?key=division
picon face 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
156 instructions.  Please criticise to your hearts content

..;=============================================================================;
; 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
ADD11 REGA,REGB
RETLW 0



__________________________________________
David C Brown
43 Bings Road
Whaley Bridge
High Peak                           Phone: 01663 733236
Derbyshire                eMail: EraseMEdcb.homespamBeGonespamKILLspamgmail.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 <walter.....spamRemoveMEbytecraft.com> wrote:

{Quote hidden}

-- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
.

<CAFo_nNrZHRfMnVUVEnhM+JFytmdiOUh+B4=yFcP42Ye51a9=0A@mail.gmail.com> quoted-printable

In reply to: <f6aa56a3-0465-bf7b-eac3-eca465ad2ae5@bytecraft.com>
See also: www.piclist.com/techref/microchip/math/index.htm?key=division
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Division routines.

month overview.

new search...