Page 285 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 285
262 Chapter 9 Implementation of C Procedures
LDX $0801 ;getgsi
INX ; add 1
STX $0801 ; put it back
and the statement lui—; in Figure 9.4 is implemented
LDX 1, SP ; get lui
DEX ; subtract 1
STX 1, SP ; put it back
When the increment or decrement operator appears in a larger expression, the initial
or final value of the variable used in the outer expression depends on whether the pair of
"+" or "-" signs appears before or after the variable. Isc = ++ guc; is implemented
unsigned char guc; int gsi;
main{){ char Isc; unsigned int lui;
guc++; Isc—; gsi++; lui—; Isc = ++guc; Isc = guc++;
}
a. A C Program
4: main(){ char Isc; unsigned int lui;
0000095B 1B9D LEAS -3,SP
5: guc++;
0000095D 720800 INC $0800
6: Isc—;
00000960 6380 DEC 0,SP
7: gsi++;
00000962 FE0801 LDX $0801
00000965 08 INX
00000966 7E0801 STX $0801
8: lui—;
00000969 EE81 LDX 1,SP
0000096B 09 DEX
0000096C 6E81 STX 1,SP
9: Isc = ++guc;
0000096E 720800 INC $0800
00000971 B60800 LDAA $0800
00000974 6A80 STAA 0,SP
10: Isc = guc++;
00000976 A680 LDAA 0,SP
00000978 720800 INC $0800
0000097B 6A80 STAA O r SP
0000097D 1B83 LEAS 3,SP
0000097F 3D RTS
b. Assembly Language Generated by Part (a)
Figure 9.4. A C Program with Incrementing and Decrementing