Searching \ for '[EE]: 8051 32x16 bit divide algorithm?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=divide
Search entire site for: '8051 32x16 bit divide algorithm?'.

Exact match. Not showing close matches.
PICList Thread
'[EE]: 8051 32x16 bit divide algorithm?'
2001\02\19@104827 by D Lloyd

flavicon
face
Hi,

My learned (or not so learned, it would seem) colleague is seeking a 32 bit
x 16 bit divide routine for the 8051 as he is whining about how it doesnt
have a decent divide etc.....

Can anyone past/present 8051 supremos help in this department?

Regards,
Dan

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@110702 by Spehro Pefhany

picon face
At 03:48 PM 2/19/01 +0000, you wrote:
>Hi,
>
>My learned (or not so learned, it would seem) colleague is seeking a 32 bit
>x 16 bit divide routine for the 8051 as he is whining about how it doesnt
>have a decent divide etc.....

Used to bigger stuff is he?

>Can anyone past/present 8051 supremos help in this department?

There should be something here that he can scab and use or adapt:

http://www.code.archive.aisnota.com/downloads/

But this is the sort of thing that is not hard to write yourself, particularly
for something like an 8051.

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@115057 by D Lloyd

flavicon
face
part 1 2985 bytes content-type:text/plain; charset=us-ascii
Hi,

Indeed I do know this gag and the ironic thing is that we have an Ozzie
working with us at the moment and he has been whining that the weather is
"too consistent" in England! (Consistently crap, I imagine).

My colleague has passes on his thanks and asks if he may have a gander at
these you have found. I think he is particulary interested in ones that use
the existing divide routine (which is of "no use to man or beast" - his
words) for some reason.

Thanks to all who have responded,

Best Regards,
Dan





(Embedded     Andy David <.....akdavidKILLspamspam.....ULTRONICS.CO.UK>KILLspamspam.....MITVMA.MIT.EDU>> image moved   19/02/2001 16:08
to file:
pic18085.pcx)





Please respond to pic microcontroller discussion list
     <
EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU>
Sent by:  pic microcontroller discussion list <PICLISTspamspam_OUTMITVMA.MIT.EDU>


To:   @spam@PICLISTKILLspamspamMITVMA.MIT.EDU
cc:
Subject:  Re: [EE]: 8051 32x16 bit divide algorithm?

Security Level:?         Internal


Dan,

I understand our cousins down under have a gag:

Q: How can you tell when an aeroplane is full of Poms?
A: The whining doesn't stop when the engines are turned off.

If your colleague promises to stop whining, he can have the 16/8-bit and
20/10-bit 8051 divide routines I've just found. They're badly documented
and
should serve well as a learning exercise. Division routines aren't that
difficult, anyway.


- Andy.
----------------------------------------------
Andrew David, Software Manager, Ultronics Ltd
http://www.Ultronics.com





> {Original Message removed}
part 2 165 bytes content-type:application/octet-stream; (decode)

part 3 136 bytes
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@120549 by Olin Lathrop

face picon face
> My learned (or not so learned, it would seem) colleague is seeking a 32
bit
> x 16 bit divide routine for the 8051 as he is whining about how it doesnt
> have a decent divide etc.....

This kind of guy should use a compiler that has all the math magic built in.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, RemoveMEolinTakeThisOuTspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@121630 by Andy David

flavicon
face
> My colleague has passes on his thanks and asks if he may have a gander at
> these you have found. I think he is particulary interested in
> ones that use
> the existing divide routine (which is of "no use to man or beast" - his
> words) for some reason.
>
> Thanks to all who have responded,

Dan,

I don't know what "the existing divide routine" is, but here's the code. I
can no longer read 8051 code very well (how's that for a disclaimer?) but
these look like long division to me.

I strongly suggest pencil, paper and a large coffee for writing all maths
routines. As well as potentially saving time that poor or incorrect code
could cost, you'll be far better off at the end.

Here's the code, hope you find these of some use. I can't even follow the
mov's...


- Andy.
----------------------------------------------
Andrew David, Software Manager, Ultronics Ltd
http://www.Ultronics.com





; Divide 16 bit number in R7,R6 by 8 bit number in B. Put result in A.

div16:  CJNE  R6,#0,calcdiv
       CJNE  R7,#0,calcdiv
       MOV   R2,#0             ; If R7:R6 is 0, then result is 0
       LJMP  dend

calcdiv:CLR   C
       MOV   A,B
       RRC   A
       MOV   R5,A

       MOV   A,#0
       RRC   A
       MOV   R4,A              ; R5,R4 is the initial divisor

       MOV   R2,#0             ; Result
       MOV   R3,#80h           ; Bit value for result

dloop:  MOV   A,R6
       CLR   C
       SUBB  A,R4              ; LS Byte subtract
       MOV   R1,A

       MOV   A,R7
       SUBB  A,R5              ; MS Byte subtract
       JC    set0              ; If carry set, subtract was not possible

       MOV   R7,A
       MOV   A,R1
       MOV   R6,A              ; R7,R6 is the new value to subtract from

       MOV   A,R2
       ADD   A,R3
       MOV   R2,A              ; Set bit in result

set0:   CLR   C
       MOV   A,R3
       RRC   A
       MOV   R3,A              ; New bit value for result
       JZ    dend              ; all bits have been done

       CLR   C
       MOV   A,R5
       RRC   A
       MOV   R5,A
       MOV   A,R4
       RRC   A
       MOV   R4,A              ; R5,R4 is new divisor

       LJMP  dloop             ; do next bit

dend:   MOV   A,R2              ; Result in A
       RET






; Divide 20 bit number in R7:R6:R5 by 10 bit number in R3:R2.
; Put result in A:B.

div20:  MOV   A,R5
       ORL   A,R6
       ORL   A,R7
       JNZ   caldiv

       SETB  RS0               ; Reg bank 1
       MOV   R7,#0
       MOV   R6,#0             ; If R7:R6:R5 is 0, then result is 0
       CLR   RS0               ; Reg bank 0
       LJMP  d20end

caldiv: MOV   R4,#0
       MOV   R1,#3             ; Divisor is already 6 left. Shift another
3.

shftsub:CLR   C
       MOV   A,R2
       RLC   A
       MOV   R2,A
       MOV   A,R3
       RLC   A
       MOV   R3,A
       MOV   A,R4
       RLC   A
       MOV   R4,A
       DJNZ  R1,shftsub        ; R4:R3:R2 is the initial sutractor

       SETB  RS0               ; Reg bank 1
       MOV   R7,#0
       MOV   R6,#0             ; Result in R7:R6 bank 1
       MOV   R5,#80h
       MOV   R4,#0             ; Bit value for result in R5:R4 bank 1
       CLR   RS0               ; Reg bank 0

d20loop:CLR   C
       MOV   A,R5
       SUBB  A,R2              ; LS Byte subtract
       MOV   R0,A

       MOV   A,R6
       SUBB  A,R3              ; Mid Byte subtract
       MOV   R1,A

       MOV   A,R7
       SUBB  A,R4              ; MS Byte subtract
       JC    res0              ; If carry set, subtract was not possible

       MOV   R7,A
       MOV   A,R1
       MOV   R6,A
       MOV   A,R0
       MOV   R5,A              ; Update subtractee

       SETB  RS0               ; Reg bank 1
       MOV   A,R6
       ORL   A,R4
       MOV   R6,A              ; Set bit in result LS Byte
       MOV   A,R7
       ORL   A,R5
       MOV   R7,A              ; Set bit in result MS Byte

res0:   SETB  RS0               ; Reg bank 1
       CLR   C
       MOV   A,R5
       RRC   A
       MOV   R5,A
       MOV   A,R4
       RRC   A
       MOV   R4,A              ; New bit value for result
       ANL   A,#20h
       CLR   RS0               ; Reg bank 0
       JNZ   d20end            ; all bits have been done

       CLR   C
       MOV   A,R4
       RRC   A
       MOV   R4,A
       MOV   A,R3
       RRC   A
       MOV   R3,A
       MOV   A,R2
       RRC   A
       MOV   R2,A              ; R4:R3:R2 is the new subtractor

       LJMP  d20loop           ; do next bit

d20end: SETB  RS0               ; Reg bank 1
       MOV   A,R7
       MOV   B,R6              ; Result in A:B
       CLR   RS0               ; Reg bank 0

       RET




________________________________________________________________________
This message has been checked for all known viruses, by Star Internet,
delivered through the MessageLabs Virus Control Centre.
For further information visit:
http://www.star.net.uk/stats.asp

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@122910 by Spehro Pefhany

picon face
At 04:49 PM 2/19/01 +0000, you wrote:
>
>My colleague has passes on his thanks and asks if he may have a gander at
>these you have found. I think he is particulary interested in ones that use
>the existing divide routine (which is of "no use to man or beast" - his
>words) for some reason.

Ah, that's what he's after. No, I don't think there is a way of using the
DIV instruction in the 8051 to speed up a multi-byte divide.

Good thought, though. It *is* possible to use the MUL instruction to speed
up multi-byte  multipication (do partial products and add).

Yes, the DIV instruction is of little use, perhaps in addressing of data
structures in memory, but MUL is usually what I end up using.

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffspamTakeThisOuTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@184720 by Bob Ammerman

picon face
----- Original Message -----
From: Spehro Pefhany <EraseMEspeffspamINTERLOG.COM>
To: <RemoveMEPICLISTEraseMEspamEraseMEMITVMA.MIT.EDU>
Sent: Monday, February 19, 2001 12:30 PM
Subject: Re: [EE]: 8051 32x16 bit divide algorithm?


> At 04:49 PM 2/19/01 +0000, you wrote:
> >
> >My colleague has passes on his thanks and asks if he may have a gander at
> >these you have found. I think he is particulary interested in ones that
use
> >the existing divide routine (which is of "no use to man or beast" - his
> >words) for some reason.
>
> Ah, that's what he's after. No, I don't think there is a way of using the
> DIV instruction in the 8051 to speed up a multi-byte divide.

I am not familiar with 8051 divide, but you can certainly use a low
precision divide to speed up a larger precision one on x86.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\02\19@200216 by Spehro Pefhany

picon face
>I am not familiar with 8051 divide, but you can certainly use a low
>precision divide to speed up a larger precision one on x86.

Divide on the 8051 divides two 8 bit unsigned quantities and leaves
an 8 bit quotient and an 8 bit remainder.

It's not used in my routines, nor in Dave Dunfield's compiler's
divide routine, Keil C51 seems to use it conditionally (only) if
the number (or numbers, I have not really traced it out) are
actually 8 bit.

Best regards,


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffTakeThisOuTspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspamspamspamBeGonemitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...