Prevents initializing a BSS section to zero to avoid uninitialized variable to be iniatialized to zero by the startup.
NO_INIT_BSS
If the variable is initialized to 0 while using the directive NO_INIT_BSS then the variable will be placed in BSS section and will not be initialized to zero ( NO_INIT_BSS Directive Usage - Example 1).
Following are few examples of using the NO_INIT_BSS directive.
LCF:
.......
GROUP : {
.__uninitialized_intc_handlertable ALIGN(0x10) : {}
.data : {}
.user_def_Init (DATA):{}
.sdata : {}
.sbss : {}
.sdata2 : {}
.sbss2 : {}
.bss : {}
.user_def_Uninit (BSS) NO_INIT_BSS :{}
} > internal_ram
.......
Test case:
#pragma section RW ".user_def_Init" ".user_def_Uninit"
// first user defined section treated as initialized section and second
// user defined section treated as uninitialized section
__declspec (section ".user_def_Init") int myvar_a;
// myvar_a goes to user_def_Uninit section as it is not initialized
__declspec (section ".user_def_Init") int myvar_b=3;
// myvar_b goes to user_def_Init section as it is initialized
__declspec (section ".user_def_Init") int myvar_c=0;
// myvar_c goes to user_def_Init section as it is initialized to zero
// But var myvar_c is not initialized to zero as it comes under
NO_INIT_BSS
int main(void) {
volatile int i = 0;
/* Loop forever */
for (;;) {
i++;
myvar_a ++;
myvar_b ++;
}
}
LCF:
.......
GROUP : {
.__uninitialized_intc_handlertable ALIGN(0x10) : {}
.data : {}
.user_def_Init (DATA):{}
.sdata : {}
.sbss : {}
.sdata2 : {}
.sbss2 : {}
.bss : {}
.user_def_Uninit (BSS) NO_INIT_BSS :{}
} > internal_ram
.......
Test case:
#pragma push //Save the original pragma context
#pragma section data_type sdata_type ".user_def_Init"
".user_def_Uninit"
unsigned int test_var; //Here variable test_var will place in the
section user_def_Uninit and NOT initializes to zero.
#pragma pop
unsigned int test_var2 = 0; //Here variable test_var2 will place in
.bss/.sbss section and initializes to zero.
LCF:
.......
GROUP : {
.__uninitialized_intc_handlertable ALIGN(0x10) : {}
.data : {}
.user_def_Init (DATA):{}
.sdata : {}
.sbss : {}
.sdata2 : {}
.sbss2 : {}
.bss : {}
.user_def_Uninit (BSS) NO_INIT_BSS :{}
} > internal_ram
.......
Test case:
#pragma push //Save the original pragma context
#pragma section data_type sdata_type ".user_def_Init"
".user_def_Uninit"
unsigned int test_var; // Variable test_var will place in the section
user_def_Uninit
#pragma explicit_zero_data on
unsigned int test_var2 = 0; // Variable test_var2 will place in the
section user_def_Init as the pragma // explicit_zero_data is enabled
#pragma explicit_zero_data reset
(OR #pragma explicit_zero_data off)
unsigned int test_var3 = 5; //Variable test_var3 will place in the
section user_def_Init
unsigned int test_var4 = 0; //Variable test_var3 will place in the
section user_def_Uninit
#pragma pop