BIT
BIT
now that you fixed the bug in the bit-acces on word , would it be possible to implement BIT as simple type ? idealy declarations of this type would automatically occupy one bit and the compiler should reserve ram accordingly. so the first 8 bit's declared would occupy just one byte of ram yet be individually accessible .
eventually i would already be happy with the possibility to declare a bit-variable inside an existing type , e.g. var MYSIGNAL : BIT @ mylongint.5
of course i would have to reserve RAM by first declaring mylongint but again , working on bit-level would be more efficient if we could acces individual bits by their own name.
JPC
eventually i would already be happy with the possibility to declare a bit-variable inside an existing type , e.g. var MYSIGNAL : BIT @ mylongint.5
of course i would have to reserve RAM by first declaring mylongint but again , working on bit-level would be more efficient if we could acces individual bits by their own name.
JPC
Re: BIT
It complicates life a lot, we have to write new interpretation for each operator, since + will not be the same for byte and for bit vars. Also, there are many controls that will have to be introduced, such as setting bit of a bit variabel. Moreover, passing a bit as a parameter is tricky. Finally, the library structure has to be expanded in order to accept the new type.
A lot of work, is it really worth it?
A lot of work, is it really worth it?
ok , i accept that it complicate's your life but we are talking about boolean math by the nature of this type. This should not be too complicated , typecasting as such already exists.
My second proposal is possibly less complicated , concerns mainly referencing to exeisting construct except for the automatic reserving of ram .
Anyway , its an idea , thanks for looking at it.
JPC
My second proposal is possibly less complicated , concerns mainly referencing to exeisting construct except for the automatic reserving of ram .
Anyway , its an idea , thanks for looking at it.
JPC
Is it complicated to get the compilers to accept a bit for boolean operations i.e. if statements. At the moment
(sorry for the C code in the Pascal forum)
the bit value is first converted to a byte and then this byte is then evaluated as a boolean value. I think this is madness and very complicated.
Thanks for listening to my rant.
Code: Select all
if(PORTA.F0)
the bit value is first converted to a byte and then this byte is then evaluated as a boolean value. I think this is madness and very complicated.
Thanks for listening to my rant.
Graham Ambrose
You probably mean:Messenga wrote:The trick here would be to use the testbit function
if (testbit(PORTA,F0))
Code: Select all
if (testbit(PORTA,F0) = 1)
TestBit tests a bit. Therefore, it cannot return 255. If you like, you can make the function TestIfBitIsOne that will return 255 and 0.Werner wrote:Testbit unfortunately does not return booleans
Anyway, the code
Code: Select all
if TestBit(portb,2) <> 0 then
Code: Select all
if TestIfBitIsOne(portb,2) then
Werner is right it does not return booleans and so if you look at code produced.
first PORTB.2 is turned into a byte value either 1 or 0
then this value (STACK_1) is evaluated
all this code code be simplified to
So you can see how this sort of thing can really bulk up the size of your code.
I have every respect for mE's work and enjoy using their tools and compilers. But with them implementing increasing complex libraries i.e. enternet which is very complicated and big I think it is important not to forget to continue to develop the basics that these libraries are built on so in response to your question.
Could the Boolean value not be introduced in stages i.e. compiler recognises Boolean expressions for if statements with out having to do a full blown Boolean type?
first PORTB.2 is turned into a byte value either 1 or 0
Code: Select all
MOVLW 0
BTFSC PORTB, 2
MOVLW 1
MOVWF STACK_1
Code: Select all
MOVLW 255
SUBWF STACK_1, W
BTFSS STATUS, Z
Code: Select all
BTFSS PORTB, 2
I have every respect for mE's work and enjoy using their tools and compilers. But with them implementing increasing complex libraries i.e. enternet which is very complicated and big I think it is important not to forget to continue to develop the basics that these libraries are built on so in response to your question.
I think yes.A lot of work, is it really worth it?
Could the Boolean value not be introduced in stages i.e. compiler recognises Boolean expressions for if statements with out having to do a full blown Boolean type?
Graham Ambrose
This is one of these things where the best way depends on what you are doing. Sometimes you are more interested in execution efficiency than RAM efficiency, in which case this is actually the best way to do it. If you are working with a lot of bits, and are short on RAM, you would be better off working with packed bits, as you describe. I would like to see a type bit (or boolean packed, or whatever) for those situations, but the assembly created will necessarily be longer, and take longer to execute. It will only be worth it in certain specific applications.gambrose wrote:the bit value is first converted to a byte and then this byte is then evaluated as a boolean value. I think this is madness and very complicated.
If you know what you're doing, you're not learning anything.
7 instructions is less efficient than 1This is one of these things where the best way depends on what you are doing. Sometimes you are more interested in execution efficiency than RAM efficiency, in which case this is actually the best way to do it.
even if you have lots of RAM and store your boolean value in it's own byte you still need 3 instructions where one would do.
Graham Ambrose
To actually perform the operation, you're correct, however the addressing of bits gets a lot more complicated. If, for example, you have an array of 256 bits, the array index has to be split into a 5-bit selector for the bytes, and then a 3-bit selector for the bits. A lot of shifting and masking. But, sometimes it would be worth it. I think that it is a good long-term goal, but I'd wager that the overall number of clock cycles and words of ROM for a typical actual usage would be higher with individual bits, just because of the overhead in addressing.gambrose wrote:7 instructions is less efficient than 1
even if you have lots of RAM and store your boolean value in it's own byte you still need 3 instructions where one would do.
If you know what you're doing, you're not learning anything.