---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id AE7B204F00FA; Wed, 28 Jan 2004 07:00:11 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <10.00CC0F6B@cherry.ease.lsoft.com>; Wed, 28 Jan 2004 10:00:02 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 0753 for PICLIST@MITVMA.MIT.EDU; Wed, 28 Jan 2004 09:59:55 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 3879; Wed, 28 Jan 2004 09:59:35 -0500 Received: from msg.ureach.com [63.236.74.36] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with ESMTP ; Wed, 28 Jan 2004 09:59:34 EST X-Warning: mitvma.mit.edu: Host msg.ureach.com claimed to be ureach.com Received: from www23.ureach.com (www23.ureach.com [172.16.2.51]) by ureach.com (8.12.9/8.12.9) with ESMTP id i0SExbbI024125; Wed, 28 Jan 2004 09:59:37 -0500 Received: (from nobody@localhost) by www23.ureach.com (8.9.3/8.9.1) id JAA28909; Wed, 28 Jan 2004 09:59:37 -0500 Received: from [68.54.126.2] by www23.ureach.com via HTTP; Wed, 28 Jan 2004 14:59:36 GMT Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-vsuite-type: e Message-ID: <200401281459.JAA28909@www23.ureach.com> Date: Wed, 28 Jan 2004 09:59:37 -0500 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: Andrew Kieran Subject: Re: [PIC:] divide by 10 question Comments: To: phil@SPIDERWEB.COM.AU To: PICLIST@MITVMA.MIT.EDU Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856117 There are many solutions, but two in particular that I would consider: 1) o starting with number to be divided in 'value1' o Shift right, store result in 'value1' and 'value2' o shift right, 'value1' two more times, storing result in 'value1' o subtract 'value2' from 'value1' o The result is the original 'value1' divided by 10 This works likes this: rrf - divides by two, store in 'value2' rrf - now divided by four rrf - now divided by eight subtract 'value2' - now divided by ten Note also that the state of the carry flag after the last shift can be used to determne whether to round-up the result 2) Alterately, I would consider using one of the general purpose division routines from the PICLIST. You should have one for your code library anyway. So unless you're code space is really tight and you don't need to do any other division, I'd use the general purpose routine rather than this specialized divide by ten approach. That's my $0.02 Andrew ________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag ---- On , Phil (phil@SPIDERWEB.COM.AU) wrote: > Hello everyone, > > I'm looking for a divide by 10 routine. The number that I want to divide is an > 8 bit number but I will very likely need to divide 10 bit numbers by ten as > well. > > While playing with micro processors during the mid 70s I remember that > dividing by ten involved a shift right and an add instruction but I cannot > remember the sequence. > > A web search has revealed many 16 bit division routines but they look more > complex than I remember for a simple divide by 10. > > Again, can someone help? > > -- > Regards, > Phil. > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics .