Page 244 - Programming Microcontrollers in C
P. 244
Header File 229
42 ; 17
43 .public _test
44 .psect _bss
45 _baker:
46 0000 .byte [1]
47 .public _baker
48 .psect _data
49 _able:
50 .byte [1]
51 .public _able
52 .end
Lines 17 through 24 correspond to the two lines
dog = able;
dog = able;
The memory location of able in the program is _able, and the
memory location for dog is at OFST-1,x. Note that the value in
_able is read and placed into dog twice as the program stated.
Also, the instruction clr _able is executed twice to account for
the two lines
able = 0;
able = 0;
This code is what you should expect when the volatile keyword is
used when able is declared. On the other hand, lines 31 through 34
show the compilation of the two C lines
dog = baker;
dog = baker;
In this case, you will note that the value for baker, stored at _baker,
is placed into the address of dog only once even though the code line
is repeated. Similarly, the two lines
baker = 0;
baker = 0;
result in assembly code that clears the location _baker only once.
This type of optimization will save you much code space. It is certainly
a problem whenever there is a memory location that can be changed
from outside the program. The volatile keyword will cause the