Searching \ for '[PIC]: Divide 24/8 routine' 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/microchip/math/index.htm?key=divide
Search entire site for: 'Divide 24/8 routine'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Divide 24/8 routine'
2002\12\21@020622 by dson Brusque (PICList)

face
flavicon
face
Hello,

   I'm trying to port the division routine at message
www.piclist.org/techref/postbot.asp?by=time&id=piclist\1996\11\08\154933a
to CCS-PCH but it's not working.

   Have anyone sucessfully ported this routine to C?

   Any other sugestion of a routine to divide a 24 bit number by a 8
bit number? Prefferably an speed optimized routine for PIC18Fxxx??? :)

   Thank you very much,

   Brusque

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

2002\12\21@100448 by Olin Lathrop

face picon face
>     I'm trying to port the division routine at message
>
www.piclist.org/techref/postbot.asp?by=time&id=piclist\1996\11\08\1
54933a
> to CCS-PCH but it's not working.

I'm probably going to get the usual flak for this, but this is exactly the
kind of low level routine that should be done in assembler, even if you
normally write most of the code in a higher level language.  This is
especially true since you are asking for an "optimized" routine.

>     Have anyone sucessfully ported this routine to C?
>
>     Any other sugestion of a routine to divide a 24 bit number by a 8
> bit number? Prefferably an speed optimized routine for PIC18Fxxx??? :)


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

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

2002\12\21@102534 by Bob Ammerman

picon face
----- Original Message -----
From: "Olin Lathrop" <olin_piclistspamKILLspamEMBEDINC.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Saturday, December 21, 2002 10:04 AM
Subject: Re: [PIC]: Divide 24/8 routine


{Quote hidden}

No flak from me, you are exactly on. But perhaps what the OP really needs to
know is how to take the assembly code and embed it in a C function using
inline assembly, or how to set it up to be linked in with and callable by
the C code. (None of which I can help with - I know nearly nothing about
CCS).

Bob Ammerman
RAm Systems

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

2002\12\21@180444 by Spehro Pefhany

picon face
At 10:22 AM 12/21/02 -0500, you wrote:


>No flak from me, you are exactly on. But perhaps what the OP really needs to
>know is how to take the assembly code and embed it in a C function using
>inline assembly, or how to set it up to be linked in with and callable by
>the C code. (None of which I can help with - I know nearly nothing about
>CCS).

I did something "hybrid" recently to get 16 x 16 -> 32 unsigned multiply,
by hacking some inline asm code into a C routine, and it was reasonably
efficient and (more importantly, as otherwise I could have used longs)
very compact. Can't share it, unfortunately. It could be broken by a future
version of the compiler, however it's very unlikely IMHO.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamspam_OUTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

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

2002\12\22@003410 by Dale Botkin

flavicon
face
On Sat, 21 Dec 2002, Bob Ammerman wrote:

> ----- Original Message -----
> From: "Olin Lathrop" <KILLspamolin_piclistKILLspamspamEMBEDINC.COM>
> > I'm probably going to get the usual flak for this, but this is exactly the
> > kind of low level routine that should be done in assembler
>
> No flak from me, you are exactly on. But perhaps what the OP really needs to
> know is how to take the assembly code and embed it in a C function using
> inline assembly, or how to set it up to be linked in with and callable by
> the C code. (None of which I can help with - I know nearly nothing about
> CCS).

No flak here either.  I just use the compiler for arithmetic operations,
but if the OP needs something truly optimized as well as the ASM code, all
he's got to do is

#ASM
<place assembly code here>
#ENDASM

You can declare variables and use their names in the asm code and do
whatever else needs doing.  That would seem to be the easiest way to
"port" asm code to C...  8-)  Anyway, it's all there in the help file,
look under #ASM in the pre-processor command summary.

Dale

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu>

2002\12\22@121948 by dson Brusque (PICList)

face
flavicon
face
Hello Bob and Olin,

  I've managed to make it work:

//
*****************************************************************************

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

byte ACCc;
byte ACCbU;
byte ACCbH;
byte ACCbL;
byte ACCdU;
byte ACCdH;
byte ACCdL;
byte ACCa;
byte Temp;

void divide2408(void)
{
#asm
  Sub_Divide:
      movlw 24           ; 24 Bit TO DIVIDE
      movwf Temp
      movf  ACCbU,W_      ; D = B
      movwf ACCdU
      movf  ACCbH,W_
      movwf ACCdH
      movf  ACCbL,W_
      movwf ACCdL
      clrf  ACCbU
      clrf  ACCbH
      clrf  ACCbL
      clrf  ACCc         ; C = 0

  dloop:
      bcf   STATUS,0     ; CARRY = 0
      rlcf  ACCdL
      rlcf  ACCdH
      rlcf  ACCdU        ; Rotate Left D
      rlcf  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:
      rlcf  ACCbL
      rlcf  ACCbH
      rlcf  ACCbU
      decfsz Temp
      goto  dloop
#endasm
}

  Thanks,

  Brusque

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu>

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