|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 589 Location: Des Moines, Iowa, USA
|
CCS has impressive bit handling. |
Posted: Tue Feb 25, 2020 1:35 pm |
|
|
I read about int1, but never used it. The compiler will use one byte for up to 8 of those:
Code: | int1 bit1;
int1 bit2;
int1 bit3;
int1 bit4;
int1 bit5;
int1 bit6;
int1 bit7;
bit0 = 1;
bit1 = 0;
bit2 = 1;
bit3 = 0;
bit4 = 1;
bit5 = 0;
bit6 = 1;
bit7 = 0;
|
Those turn into nice atomic assembly calls:
Code: | .................... bit0 = 1;
00228: BSET.B 800.0
.................... bit1 = 0;
0022A: BCLR.B 800.1
.................... bit2 = 1;
0022C: BSET.B 800.2
.................... bit3 = 0;
0022E: BCLR.B 800.3
.................... bit4 = 1;
00230: BSET.B 800.4
.................... bit5 = 0;
00232: BCLR.B 800.5
.................... bit6 = 1;
00234: BSET.B 800.6
.................... bit7 = 0;
00236: BCLR.B 800.7 |
So I wondered how different it was to doing it manually.
Just SETTING a bit like this is larger:
Code: | .................... byte = (1 << 4);
00238: MOV.B #10,W0L
0023A: MOV.B W0L,801 |
But ORing a bit generates the same nice code without needing to use non-standard int1:
Code: | .................... byte = byte | (1 << 4);
0023C: BSET.B 801.4 |
Clearing a bit also generates one atomic instruction:
Code: | .................... byte = byte & ~(1 << 4);
0023E: BCLR.B 801.4 |
Kudos to CCS. It's nice seeing int1 available, but nicer seeing the compiler is smart enough to do bit set/clear efficiently if you are manually doing it.
I created Arduino-compatible bit macros and worried they might generate bulky code, but I never checked until now:
Code: | .................... byte = bitSet(byte, 4);
0023C: BSET.B 801.4
.................... byte = bitClear(byte, 4);
00242: BCLR.B 801.4 |
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Tue Feb 25, 2020 5:19 pm |
|
|
Really has nothing to do with CCS, thank MICROCHIP ! They're the ones that embedded bit instructions in the PIC !! |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 589 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Feb 26, 2020 1:32 pm |
|
|
temtronic wrote: | Really has nothing to do with CCS, thank MICROCHIP ! They're the ones that embedded bit instructions in the PIC !! |
I am glad to give credit to CCS for actually taking advantage of it I've seem some terrible code generation over the years, so I'm always pleased when I see a compiler doing something smart.
I noticed that bit set/clear when looking at the I2C assembly. Nice. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|