Page 281 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 281
258 Chapter 9 Implementation of C Procedures
However, without optimization, the intermediate values are generally computed using the
largest precision of the variables in the expression (extending the precision called
upcasting). Although many C compilers do all arithmetic in the largest precision, 16
bits in our case, HiWare efficiently operates upon numbers in the smallest possible
precision.
unsigned char guc; int gsi;
main(){ char Isc; unsigned int lui;
gsi = lui + 12; guc = Isc - 33;
guc = lui + 9; gsi = gsi + Isc; lui = guc - 17;
}
a. C Program
4: main(){ char Isc; unsigned int lui;
main:
0000095B 1B9D LEAS -3,SP
5: gsi = lui + 12;
0000095D EE80 LDX 0,SP
0000095F 1AOC LEAK 12,X
00000961 7E0801 STX $0801
6: guc = Isc - 33;
00000964 A682 LDAA 2,SP
00000966 8021 SUBA #33
00000968 7A0800 STAA $0800
7: guc = lui + 9;
0000096B E681 LDAB 1,SP
0000096D CB09 ADDB #9
0000096F 7B0800 STAB $0800
8: gsi = gsi + Isc;
00000972 A682 LDAA 2,SP
00000974 B704 SEX A,D
00000976 F30801 ADDD $0801
00000979 7C0801 STD $0801
9: lui = guc - 17;
0000097C F60800 LDAB $0800
0000097E 87 CLRA
0000097F 830011 SUBD #17
00000983 6C80 STD 0,SP
10: }
00000984 1B83 LEAS 3,SP
00000986 3D RTS
b. Assembly Language Generated by Part (a)
Figure 9.2. A C Program with Local and Global Variables