Page 303 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 303
280 Chapter 9 Implementation of C Procedures
int a;
void main() { int b; b = power(&a, 2); }
int power(int *i, unsigned char j) { int n ~ 1;
while( j— ) n = n * *i; return n;
}
a. A C Procedure calling a Subroutine
00000976 CC0800 LDD #2048
00000979 3B PSHD
0000097A C602 LDAB #2
0000097C 07DD BSR *-33 ;abs = 095B
0000097E 3A PULD
0000097F 3D RTS
b. Assembly Language for the Calling Procedure in Part (a)
0000095B CE0001 LDX #1
4: while( j— ) n = n * *i;
0000095E B710 TFR B,A
00000960 200B BRA *+13 ;abs = 096D
00000962 ED82 LDY 2,SP
00000964 36 PSHA
00000965 EC40 LDD 0,Y
00000967 B756 TFR X,Y
00000969 13 EMUL
0000096A B745 TFR D,X
0000096C 32 PULA
0000096D 36 PSHA
0000096E 43 DECA
0000096F E6BO LDAB 1,SP+
00000971 26EF BNE *-15 ;abs = 0962
5: return n;
00000973 B754 TFR X,D
00000975 3D RTS
c. Assembly Language for the Called Procedure in Part (a)
Figure 9.14. A Subroutine to Raise a Number to a Power
SP->
inside the
subroutine
Figure 9.15. Stack for power Procedure