HOW DOES PBP handle bits varables to bytes


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default HOW DOES PBP handle bits varables to bytes

    Hi Guys , was wondering how PBP handles bits var defines , relative to byte defines. for use of memory code space use.

    when i have a need of many flags i have generally defined a byte , and then allocated each bit of that byte to the var flag names as required ,


    Code:
     bit_byte1 var byte 
       bit0 var bit_byte1.0
       bit1 var bit_byte1.1
       bit2 var bit_byte1.2
       bit3 var bit_byte1.3
       bit4 var bit_byte1.4
       bit5 var bit_byte1.5
       bit6 var bit_byte1.6
       bit7 var bit_byte1.7
    
    ' need only 1 bit then 
    
    mybit  var  Bit
    where when i need only 1 bit i define as a bit only

    this is done in the assumption that when is compiled the memeory use will be less than if i had defined a byte

    does this hold true ?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    bit_byte1 var byte
    bit0 var bit_byte1.0
    bit1 var bit_byte1.1
    bit2 var bit_byte1.2
    bit3 var bit_byte1.3
    bit4 var bit_byte1.4
    bit5 var bit_byte1.5
    bit6 var bit_byte1.6
    bit7 var bit_byte1.7


    uses 1 byte

    mybit var Bit

    uses 1 byte

    mybit0 var Bit
    mybit1 var Bit


    I think uses 2 bytes .

    you can verify this by checking your ????.lst file after compiling ????.pbp

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    As best I remember if you assign 1 bit it will use a byte unless it is a bit of a named byte.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    AAAAAAGh Richard outdrew me . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    Quote Originally Posted by richard View Post
    [COLOR="#00FF00"]bit_byte1 var byte
    mybit0 var Bit
    mybit1 var Bit


    I think uses 2 bytes .
    Not necessarily. Compiler makes best use of memory and packs the bits in bytes when possible.

    So if you declare the above bit variable, they are going to be in one byte. The ninth bit will be in new byte location.

    Ioannis

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    Hi,
    I've looked at this and although I'm not that good at assembly here how I believe it works.
    When you create a BIT variable the compiler allocates a BYTE of RAM and calls it PB1, your bit variable is then defined as the first bit in that byte. When you create a second BIT variable it gets defined as the second bit in the previously allocated BYTE (ie still only a single byte). When you create the 9th BIT variable a new BYTE is allocated (PB2) and so on. So, one BIT variable takes 1 BYTE but 8 bit variables still only takes ONE byte.

    Basically, this is what it looks like in the assembly listing:
    Code:
    00081 PB01                            EQU     RAM_START + 019h
    00083 PB02                            EQU     RAM_START + 01Ah
    00092 #define _myBit1                  PB01, 000h
    00093 #define _myBit2                  PB01, 001h
    00094 #define _myBit3                  PB01, 002h
    00095 #define _myBit4                  PB01, 003h
    00096 #define _myBit5                  PB01, 004h
    00097 #define _myBit6                  PB01, 005h
    00098 #define _myBit7                  PB01, 006h
    00099 #define _myBit8                  PB01, 007h
    00100 #define _myBit9                  PB02, 000h
    As you can see, for 9 BIT variables only TWO bytes of RAM is allocated - thankfully and as expected.

    /Henrik.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    that's good to know , after misreading the manual at some stage I have been micro-managing bit vars needlessly for years .

  8. #8
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    Good question and answers!
    Like Richard, I have also been doing the same when it was already taken care of.
    Louie

  9. #9
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: HOW DOES PBP handle bits varables to bytes

    Thanks guys very good to know , i have been looking at this part of my code for defines and its memory use

    cheers

    Sheldon

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Configuation bits setting in PBP
    By Max_Gauss in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th September 2010, 19:25
  3. Pickit 2 saving varables?
    By jessey in forum Off Topic
    Replies: 5
    Last Post: - 7th June 2010, 10:14
  4. 16/32 bits PIC support in PBP?
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 9th May 2010, 16:40
  5. Bits & Bytes
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th April 2006, 12:52

Members who have read this thread : 2

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