32 bit Addition - How to ?


Closed Thread
Results 1 to 5 of 5
  1. #1
    capitano's Avatar
    capitano Guest

    Post 32 bit Addition - How to ?

    Is possible in Pic Basic Pro make an addition at 32 bit ?

    This is my problem


    i var word


    :loop

    x=x+i ' x is variable at 32 bit


    ' program



    goto loop

    Can you help me please....
    Last edited by capitano; - 28th December 2004 at 09:15.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Firstly you cannot have a single 32 bit variable defined in PICBasic so we define two 16 bit variables...

    xlow var word ' as the lower bits 15-0
    xhigh var word ' as the upper bits 31-16

    together xhigh and xlow make up your 32 bits...

    Now consider this...

    xlow=xlow+i
    if xlow < i then xhigh=xhigh+1

    here we assume that variable i is also a word...

    If the addition of variable i to xlow (the lower 16 bits of our 32 bit word) causes an overflow within xlow, the resultant will be less than variable i itself. If this occurs then simply carry 1 to the upper 16 bits residing in xhigh.

    Melanie

  3. #3
    capitano's Avatar
    capitano Guest


    Did you find this post helpful? Yes | No

    Smile 32 bit addition

    Thank you ... now i try it....

  4. #4
    capitano's Avatar
    capitano Guest


    Did you find this post helpful? Yes | No

    Post 32 bit subtraction

    Thank

    The routine of addiction work fine, i try to make subtraction routine

    xlow=xlow-i
    if xlow > i then xhigh=xhigh-1

    Can be it ?
    I try but it don't work fine...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Of course your subtraction doesn't work... how were you taught math at school when your teacher told you how to subtract numbers? Whatever you 'borrow' from the preceeding column has to be added into the column you are working on. Apply the same subtraction method you were taught when you were seven years old here. xhigh and xlow are simply your two columns of numbers.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  3. 32 bit data displaying on LCD
    By selahattin in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th September 2006, 13:33
  4. 32 bit addition
    By ice in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th May 2005, 11:23
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts