Connect with us

help on multiplying on 8051

Discussion in 'Electronic Basics' started by [email protected], Feb 22, 2004.

  1. Guest

    hi
    for a project i should multiply a port content that can be ( 1 to
    25000000)
    to 85.899346 whit assambly what should i do?
    notice that the input can be for example 13543.68 or so ! but ( at
    most 2 digit for floating in input so we don't have 23657.687)
    any help would be most appriciated
     
  2. From what you've written it's impossible to tell what you really want
    to do. However, if all you want to do is multiply a decimal number by
    a constant, just do it as you would by hand; one symbol at a time
    (since the 8051 has no decimal multiply). If the multiplicand is in
    binary, then you can do it eight bits at a time (symbol = 8 bits).
     
  3. It is not at all clear what you are trying to do. An 8051 port only
    has 8 bits, so can only represent numbers from 0 - 255 (or -128 to
    +127). Even using two ports, you can only count to 65535.

    For anyone to be able to give a useful answer, you would need to
    describe the internal (binary) format that you are using for floating
    point numbers.



    --
    Peter Bennett, VE7CEI
    peterbb (at) interchange.ubc.ca
    new newsgroup users info : http://vancouver-webpages.com/nnq
    GPS and NMEA info: http://vancouver-webpages.com/peter
    Vancouver Power Squadron: http://vancouver.powersquadron.ca
     
  4. John Jardine

    John Jardine Guest

    The question's a bit unclear.
    But, for multiplying two numbers with fixed decimal precisions it's quite
    easy to pretend the number(s) are whole integer values and write an integer
    "n byte" multiply routine that that will handle the number of bits that can
    result. This result is then passed onto another routine that integer divides
    the previous answer by the 10 or 100 or 1000 ect that the original was
    changed by. The result (integer bits and 'remainder' bits) is then converted
    back to BCD, decimal, ascii etc.

    Eg The port number might be "12,345,678.90". You know there's only ever two
    decimal digits, so call that number "1234567890". (ie. pretend it is 100
    times bigger.). The number can now be stored in memory as 4 bytes (32 bits
    of binary).
    Now pretend the multiplier is "85899346" (ie a million times bigger). Store
    this also as 4 bytes of memory.

    Code up or find a "32 bit x 32 bit" multplier routine. Use this to multiply
    your two 32 bit numbers. The routine will result in an 8 byte (64 bits)
    answer.

    This 8 byte answer now needs dividing back down by "100" and "1000000" (ie
    divide the 64 bit (binary) answer by 100 million).
    Write or find a "64 bit by 32 bit" divide routine.
    Convert the "100 million" into into a 4 byte (32 bit) binary number. (this
    value will always be the same for each calculation). Do the division of
    your 64 bit and 32 bit numbers.
    This is the final answer (in binary of course). So convert this number
    (integer part plus the 'remainder' part ) back into BCD etc.

    The 'n' byte multiply and divide routines are quite small, understandable
    and are standard use for machine code programming. A search on the web
    should turn up lots of examples.

    regards
    john
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-