In SX Microcontrollers, SX/B Compiler and SX-Key Tool, mrchadwickusa wrote: Hi John, Here is a revised version that uses WDATA to look up the divisor. I also changed the test order to speed that up a little. Converting 12345d the original with the wrdDivisor= wrdDivisor / 10 took 505.5 us at a 4Mhz clock, using the data statements it takes 130.5 uS. This compares to 45.25 for the assembly version using Golovchenko's code. I'm going to do an SXB version of Golovchenko's code using the data lookup to see how that compares. In the mean time, here is the revised subtract by powers of 10 code using WDATA with work around for the READ bug when using word values. I also made a tiny change that allows you to set BLANK as a constant to either 0, if you want BCD nibbles, or $30 if you want ASCII digits. [code] '--------------------------------------------------------------------------- Bin16DEC: ' Use: Bin16DEC word ' -- Convert a 16bit binary variable into a decimal value. ' define BLANK as 00h for BCD nibbles ' define BLANK as 30h to directly output ASCII ' to a terminal or LCD. ' Original versions by Bean (Hitt Consulting) & Michael Chadwick ' ' Setup ' wrdTemp var WORD ' wrcDivisor var WORD ' ascDigit var Byte(5) IF __PARAMCNT = 1 THEN ' if parameter is a Byte or Word variable wrdTemp = __PARAM1 ELSE wrdTemp = __WPARAM12 ENDIF ' fill all locations with blanks PUT ascDigit(0), BLANK, BLANK, BLANK, BLANK, BLANK 'updated line x1 = 4 ' position in array wrdDivisor = -10000 ' set initial power of 10 Bin16DEC1: inc ascDigit(x1) ' assume we will succeed in subtraction wrdTemp = wrdTemp + wrdDivisor ' try the subtraction if C = 1 then Bin16DEC1 ' OK, try again dec ascDigit(x1) wrdTemp = wrdTemp - wrdDivisor dec x1 ' decrement position counter if x1 = 0 THEN Bin16DEC2 ' more digits to process? x1= x1 SHL 1 ' * 2 as a work around for the read bug READ divisors + x1, wrdDivisor wrdDivisor= 0-wrdDivisor x1= x1 SHR 1 ' / 2 as work around for the read bug goto Bin16DEC1 Bin16DEC2: ascDigit(x1) = ascDigit (x1) + wrdTemp_LSB ' take care of last (right most) digit RETURN divisors: WDATA 1,10,100,1000 [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=138199#m138313 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)