Save some bytes in program memory


Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132

    Default Save some bytes in program memory

    Say you want to increment a variable and check the upper limit.

    One way is this:
    Code:
    if index<3 then
        index=index+1
    else
        index=0
    endif
    which compiles for a 16F877 to 16 bytes.

    Using this one:
    Code:
    index=index+1 & 3
    compiles to 12 bytes.

    And even better:
    Code:
    index=index+1 
    index=index & 3
    compiles to 7 bytes only!

    Ioannis

    P.S. Thanks to Mike K8LH for spotting a typo error.
    Last edited by Ioannis; - 7th February 2012 at 11:12. Reason: typo

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