Working with 3 byte numbers


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You don't even need to mess with assembler. Here's a really simple example,
    and it's all in BASIC;
    Code:
      A VAR WORD
      B VAR WORD
      X VAR BYTE
      NumToAdd VAR BYTE
      NumToAdd = $2E
        
    MAIN:
        A = $0001
        B = $FFFE
        FOR X = 1 TO NumToAdd
          B = B + 1
          IF B = 0 THEN A = A + 1
        NEXT X
    You can extend this to pretty much any size variable you need.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Why so complex? Again all in PBP... assuming positive numbers only...

    A, B and C must all be the same type (ie all WORDS or all BYTES).

    C=A+B
    If C < A then Goto SumOverflow

    Actually, B can be a BYTE if C & A are WORDS and it still will hold water.


    Extending this to the original post...
    Code:
    AHighWord var Word
    ALowWord var Word
    BByte var Byte
    CHighWord var Word
    CLowWord var Word
    
    AHighWord=$0001
    ALowWord=$FFFE
    BByte=$2E
    
    CHighWord=AHighWord
    CLowWord=ALowWord+BByte
    If CLowWord < ALowWord then CHighWord=CHighWord+1
    or without using the variable C...
    Code:
    ALowWord=ALowWord+BByte
    If ALowWord < BByte then AHighWord=AHighWord+1
    Actually in both above examples, BByte can be replaced with BWord and it'll still work.

Similar Threads

  1. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  2. Replies: 4
    Last Post: - 15th April 2009, 01:54
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

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