Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Math Help — Parallax Forums

BS2 Math Help

ArchiverArchiver Posts: 46,084
edited 2004-06-08 15:48 in General Discussion
I could use some help or clarification with some BS2 math.

Using the the Multiply High operator (**) returns the upper byte if there is
an overflow.

For example:

24,414 * 4096 = 100,000,000.00, but the stamp should return a value of $E100

while'

24414 ** 4096 will return $5F5

How can I use the Multiply High operator along with the lower byte result to
extract 1000 from 100,000,000.00 (combining the result of the * and the **
operators)?

Or.....
24414 * 2000 = 48,828,000, but again the stamp will return only the lower
byte of $0E60

and 24414 ** 2000 will return $2E9

The end result I would want from this operation is 4882 (actually 0.4882, but
I can deal with the decimal point and leading zero easy enough if I can
extract 4882).

I cannot seem to figure out the algorithm using the * and ** operators to get
the desired results described above.

Is it possible, and can somebody get me pointed in the right direction, or is
the direction a PAKI from AWC or a uM-FPU co-processor to work with the stamp?

Thanks for the feedback.

Ken


[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 09:21
    Hi Ken,

    This might be a good time to dig into...
    http://www.emesystems.com/BS2math6.htm

    There is a program there that kicks out the decimal digits of the
    double precision number
    /BS2math6.htm#showdubdec

    You have a 32 bit number broken into two words in the Stamp

    ' example
    elephant0 = 24414 * 4096 ' low word = $E100 = 57600
    elephant1 = 24414 ** 4096 ' high word = $5f5 = 1525
    DEBUG IHEX elephant1, HEX elephant0 ' prints $5f5e100
    ' which is 100000000 in decimal.

    To get the answer in decimal, you have to program in a conversion
    from base 2 to base 10. The Stamp does that for you with single
    words, but not double precision. There is no easy way.

    It is really base 2^16=65536, word-size chunks, written like this:

    100000000 = 1525 * 65536 + 57600

    The high word contains 1525, and 57600 is in the low word. The
    algorithm divides that double precision number repeatedly by 10 to
    get a quotient and a remainder until it extracts all the base 10
    digits.

    Yes, you can do that with a coprocessor, but from the standpoint of
    program execution, balance the time required for the algorithm
    against the time it takes to move the operands into and out of the
    coprocessor.

    -- Tracy


    >I could use some help or clarification with some BS2 math.
    >
    >Using the the Multiply High operator (**) returns the upper byte if there is
    >an overflow.
    >
    >For example:
    >
    >24,414 * 4096 = 100,000,000.00, but the stamp should return a value of $E100
    >
    >while'
    >
    >24414 ** 4096 will return $5F5
    >
    >How can I use the Multiply High operator along with the lower byte result to
    >extract 1000 from 100,000,000.00 (combining the result of the * and the **
    >operators)?
    >
    >Or.....
    >24414 * 2000 = 48,828,000, but again the stamp will return only the lower
    >byte of $0E60
    >
    >and 24414 ** 2000 will return $2E9
    >
    >The end result I would want from this operation is 4882 (actually 0.4882, but
    >I can deal with the decimal point and leading zero easy enough if I can
    >extract 4882).
    >
    >I cannot seem to figure out the algorithm using the * and ** operators to get
    >the desired results described above.
    >
    >Is it possible, and can somebody get me pointed in the right direction, or is
    >the direction a PAKI from AWC or a uM-FPU co-processor to work with the stamp?
    >
    >Thanks for the feedback.
    >
    >Ken
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-07 09:38
    Thank you Tracy.

    Time required for the algorithm should not be a factor, unless it takes more
    than 200mS or so. I will check it out.

    I will visit the links suggested, and should be on my way.

    Thank you again,

    Ken

    ==========================
    Yes, you can do that with a coprocessor, but from the standpoint of
    program execution, balance the time required for the algorithm
    against the time it takes to move the operands into and out of the
    coprocessor.

    -- Tracy


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-08 00:37
    Tracy,

    Thanks again for the link to your websight on Basic Stamp Math. The
    conversion to extract the decimal digits work great.....but you already knew
    that!!!!!!!!!!

    Dang, beat my head against a wall for a week after I learned about the **
    operator, I obviously could not figure out how to extract the data from the
    double precision number. Also, thanks for explaining the algorithm, that goes a lot
    farther than just posting the code.

    I found what I believe is a typo in the web page
    http://www.emesystems.com/BS2math6.htm#multiplication

    <snip>
    loop:
    debug cr,"xxxx:"
    serin 16,$54,[noparse][[/noparse]hex4 x0] ' you enter the first number (HEX)
    debug cr,"yyyy:"
    serin 16,$54,[noparse][[/noparse]hex4 y0] ' you enter the second number (HEX)

    z0= x0 * y0 ' low word of product
    z1= x0 ** x0 ' high word of product
    <end snip>

    Please correct me if wrong, the last line should read:

    z1=x0 ** y0.....not z1=x0 ** x0

    Yes/No?

    Ken

    =================

    This might be a good time to dig into...
    http://www.emesystems.com/BS2math6.htm

    There is a program there that kicks out the decimal digits of the
    double precision number
    /BS2math6.htm#showdubdec


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-06-08 15:48
    Hi Ken,

    Thanks for the feedback. I went in and corrected that typo with x0 ** y0.

    -- best regards,
    Tracy


    >Tracy,
    >
    >Thanks again for the link to your websight on Basic Stamp Math. The
    >conversion to extract the decimal digits work great.....but you already knew
    >that!!!!!!!!!!
    >
    >Dang, beat my head against a wall for a week after I learned about the **
    >operator, I obviously could not figure out how to extract the data from the
    >double precision number. Also, thanks for explaining the algorithm,
    >that goes a lot
    >farther than just posting the code.
    >
    >I found what I believe is a typo in the web page
    >http://www.emesystems.com/BS2math6.htm#multiplication
    >
    ><snip>
    >loop:
    >debug cr,"xxxx:"
    >serin 16,$54,[noparse][[/noparse]hex4 x0] ' you enter the first number (HEX)
    >debug cr,"yyyy:"
    >serin 16,$54,[noparse][[/noparse]hex4 y0] ' you enter the second number (HEX)
    >
    >z0= x0 * y0 ' low word of product
    >z1= x0 ** x0 ' high word of product
    ><end snip>
    >
    >Please correct me if wrong, the last line should read:
    >
    >z1=x0 ** y0.....not z1=x0 ** x0
    >
    >Yes/No?
    >
    >Ken
    >
    >=================
    >
    >This might be a good time to dig into...
    > http://www.emesystems.com/BS2math6.htm
    >
    >There is a program there that kicks out the decimal digits of the
    >double precision number
    > /BS2math6.htm#showdubdec
    >
    >
    >[noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >Yahoo! Groups Links
    >
    >
    >
    >
Sign In or Register to comment.