PDA

View Full Version : HOW DOES PBP handle bits varables to bytes



longpole001
- 11th July 2014, 05:51
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 ,




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 ?

richard
- 11th July 2014, 07:41
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

Archangel
- 11th July 2014, 07:42
As best I remember if you assign 1 bit it will use a byte unless it is a bit of a named byte.

Archangel
- 11th July 2014, 07:43
AAAAAAGh Richard outdrew me . . .

Ioannis
- 11th July 2014, 08:53
bit_byte1 var byte
[COLOR="#00FF00"]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

HenrikOlsson
- 11th July 2014, 09:00
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:


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.

richard
- 11th July 2014, 09:26
that's good to know , after misreading the manual at some stage I have been micro-managing bit vars needlessly for years .

LinkMTech
- 11th July 2014, 17:31
Good question and answers!
Like Richard, I have also been doing the same when it was already taken care of.

longpole001
- 18th July 2014, 11:13
Thanks guys very good to know , i have been looking at this part of my code for defines and its memory use

cheers

Sheldon