adding 32bit numbers in 16bit processor

Discussion in 'VHDL' started by isnullpr@gmail.com, Oct 15, 2006.

  1. Guest

    If I had a 16 bit processor, how do I add two 32 bit numbers with it?
     
    , Oct 15, 2006
    #1
    1. Advertising

  2. Adrian Jongenelen

    Joined:
    Sep 27, 2006
    Messages:
    5
    Location:
    Wellington, New Zealand
    Think about how you do arithmetic in your head with base 10.

    75
    +58
    ----
    133

    5+8 = 3 + 1 carry
    7 + 5 + 1 carry = 13
     
    Adrian Jongenelen, Oct 16, 2006
    #2
    1. Advertising

  3. PeteS Guest

    wrote:
    > If I had a 16 bit processor, how do I add two 32 bit numbers with it?


    Search for 'multiple precision addition'


    Cheers

    PeteS
     
    PeteS, Oct 16, 2006
    #3
  4. schrieb:
    > If I had a 16 bit processor, how do I add two 32 bit numbers with it?


    Every addition generates a carry-out. Therefore the carry-out from the
    addition of the lower word has to be added during the addition of the
    upper word.

    Ralf
     
    Ralf Hildebrandt, Oct 16, 2006
    #4
  5. IsNull Guest

    OK, so first I add the lower 16 bits of each number.Then add the top 16
    bits of each number, and to that I add the carry-out from adding the
    bottom 16 bits...correct?... but how do I separate the upper bits from
    the lower bits? is there some operation or instruction for that?
    something like a ShiftR or ShiftL?

    thanks for the help!

    Ralf Hildebrandt wrote:
    > schrieb:
    > > If I had a 16 bit processor, how do I add two 32 bit numbers with it?

    >
    > Every addition generates a carry-out. Therefore the carry-out from the
    > addition of the lower word has to be added during the addition of the
    > upper word.
    >
    > Ralf
     
    IsNull, Oct 16, 2006
    #5
  6. Frank Buss Guest

    IsNull wrote:

    > but how do I separate the upper bits from
    > the lower bits? is there some operation or instruction for that?
    > something like a ShiftR or ShiftL?


    If you have this:

    signal foo: unsigned(32 downto 0);

    you can select the upper bits like this:

    foo(31 downto 16)

    --
    Frank Buss,
    http://www.frank-buss.de, http://www.it4-systems.de
     
    Frank Buss, Oct 16, 2006
    #6
  7. PeteS Guest

    IsNull wrote:
    > OK, so first I add the lower 16 bits of each number.Then add the top 16
    > bits of each number, and to that I add the carry-out from adding the
    > bottom 16 bits...correct?... but how do I separate the upper bits from
    > the lower bits? is there some operation or instruction for that?
    > something like a ShiftR or ShiftL?
    >
    > thanks for the help!
    >
    > Ralf Hildebrandt wrote:
    >
    >> schrieb:
    >>
    >>>If I had a 16 bit processor, how do I add two 32 bit numbers with it?

    >>
    >>Every addition generates a carry-out. Therefore the carry-out from the
    >>addition of the lower word has to be added during the addition of the
    >>upper word.
    >>
    >>Ralf

    >
    >


    I don't know if you are doing this with a processor or in HDL of some
    description.

    Here it is in pseudocode for a processor

    we have two numbers - a and b, made up of a[low], a[high], b[low],
    b[high], and a result r[low], r[high].

    I'll note an important point at the end

    Add a[low], b[low] -> r[low]. This may generate a carry, which we use below

    add a[high], b[high], carry -> r[high]

    There may be a final carry. If you add two values of precision n bits,
    the result can have n+1 bits. That's why you chain the carry from the
    low order addition.

    In HDL, it's not any more work (especially if you use the primitives
    with most compilers).

    Cheers

    PeteS
     
    PeteS, Oct 16, 2006
    #7
  8. IsNull Guest

    ok, I see what you are saying..., I'm dealing with a 16-bit accumulator
    based processor, I'm trying to figure out a good way of adding 32-bit
    numbers with it using its assembly language... I only have 1 register
    which is the accumulator and a very limited group of intuctions on its
    instruction set.(instructions: Add, Addi, Load, Loadi,Comp,
    ShR,BrN,BrNi,Jump,Jumpi,Store,Storei). for example:, if I were to add
    4+3 and store it on memory location 1008 the code looks something like
    this:
    andi 0 # resets accumulator to 0
    addi 4 # adds 4 to the accumulator
    storei 1000 # stores the value on memory address 1000
    andi 0
    addi 3
    storei 1004
    loadi 1000
    addi 1004
    storei 1008

    It's simple but confusing if you are used to x86 or MIPS programming.
    so I'm trying to write something like that to add 32bit numbers...

    thanks.

    PeteS wrote:
    > IsNull wrote:
    > > OK, so first I add the lower 16 bits of each number.Then add the top 16
    > > bits of each number, and to that I add the carry-out from adding the
    > > bottom 16 bits...correct?... but how do I separate the upper bits from
    > > the lower bits? is there some operation or instruction for that?
    > > something like a ShiftR or ShiftL?
    > >
    > > thanks for the help!
    > >
    > > Ralf Hildebrandt wrote:
    > >
    > >> schrieb:
    > >>
    > >>>If I had a 16 bit processor, how do I add two 32 bit numbers with it?
    > >>
    > >>Every addition generates a carry-out. Therefore the carry-out from the
    > >>addition of the lower word has to be added during the addition of the
    > >>upper word.
    > >>
    > >>Ralf

    > >
    > >

    >
    > I don't know if you are doing this with a processor or in HDL of some
    > description.
    >
    > Here it is in pseudocode for a processor
    >
    > we have two numbers - a and b, made up of a[low], a[high], b[low],
    > b[high], and a result r[low], r[high].
    >
    > I'll note an important point at the end
    >
    > Add a[low], b[low] -> r[low]. This may generate a carry, which we use below
    >
    > add a[high], b[high], carry -> r[high]
    >
    > There may be a final carry. If you add two values of precision n bits,
    > the result can have n+1 bits. That's why you chain the carry from the
    > low order addition.
    >
    > In HDL, it's not any more work (especially if you use the primitives
    > with most compilers).
    >
    > Cheers
    >
    > PeteS
     
    IsNull, Oct 16, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. McBooCzech

    sources for DOS-16bit

    McBooCzech, Dec 10, 2004, in forum: Python
    Replies:
    3
    Views:
    463
    Adam DePrince
    Dec 11, 2004
  2. Jason B

    16bit RGB with Image module

    Jason B, Mar 27, 2007, in forum: Python
    Replies:
    2
    Views:
    530
    Will McGugan
    Mar 27, 2007
  3. brahatha
    Replies:
    1
    Views:
    672
  4. Robin Becker

    16bit hash

    Robin Becker, Jun 27, 2007, in forum: Python
    Replies:
    16
    Views:
    1,042
    Paul Rubin
    Jun 29, 2007
  5. Sebastian Gibb
    Replies:
    5
    Views:
    935
    Jorgen Grahn
    Jun 27, 2010
Loading...

Share This Page