The difference between global variables and variables declared mainly in ARM C

I am trying to use Cin Keilto write test code for mine TM4C123G, which uses a microcontroller ARM. I have no idea about ARM assembly, but in the past I wrote assembly code for AVR microcontroller.

Where are variable values ​​stored if we declare a variable in C as global, rather than declare it in main?

Are there general guidelines on whether to declare a variable global, and not in main(when it comes to writing C for the microcontroller)?

+4
source share
3 answers

The globals in ARM cause an offset to be placed in the pool area of ​​the calling function. In general, each global needs its own compensation. If you decide to use global variables, put them in a single structure so that all variables can be obtained through the pool offset singel.

Variables defined at the function level are on the stack. For reasonable reasons, this can be accessed with a simpler offset from the stack register and, as a rule, a more efficient operation code with a touch code and, possibly, cache memory, depending on which system you are using.

? , , . - , ( , , , ...), - . ( ...), , .

. , , , . , , .

+2
  • "" "bss". , . , .
  • , / . - .

"" . , , . - - , .

+1

, , , , . , , .

... , , , . , / , C ( ), . , . (, ). , , .

, C- , ( , , ). , , . , , , , - , - .

( ) , .

C, , - , , .

, , , , .. - , - , -, , , , , , , , 30 , , . , , ( ), , , , . , ( ), , , , . , , , , , , , . , . , , .

, , C . , . , /.

, , , , . / , , , . , , .data. , , , . CISC, , . RISC , . .

ram ( ). x86 , . mips arm , .

, , , . , , , , , , , .

, vs , vs unsigned vs pointer vs array - , .

0

All Articles