CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Stupid question - why no function calls

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sherpa Doug
Guest







Stupid question - why no function calls
PostPosted: Wed Apr 02, 2003 11:01 am     Reply with quote

Maybe my brain is fried but I can't see why this code does not generate calls from Main to my functions:

#include <16C58A.h>
#use delay(clock=20000000)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B7)

char key;

void Freq();
void DelaySet();
void BurstLen();
void Ping();

void main() {

setup_counters(RTCC_INTERNAL,WDT_1152MS);

while (1) { //Main polling loop
Freq();
BurstLen();
DelaySet();
Ping();
} //while(1)
} //main()

void Freq() {
key = getch();
} //Freq

void BurstLen(){
key = getch();
} //BurstLen

void Ping() {
puts("PING");
} //Ping

void DelaySet(){
key = getch();
} //DelaySet


The code generated for the while loop is:
0000 00211 .................... while (1) { //Main polling loop
0000 00212 .................... Freq();
0000 00213 .................... BurstLen();
0000 00214 .................... DelaySet();
0000 00215 .................... Ping();
0000 00216 .................... } //while(1)
007E 0A65 00217 GOTO 065

The compiler is PCB ver 3.110


___________________________
This message was ported from CCS's old forum
Original Post ID: 13316
Tomi
Guest







Re: Stupid question - why no function calls
PostPosted: Wed Apr 02, 2003 12:12 pm     Reply with quote

Your functions are compiled as inline.
Here is the list (different addresses I think):

005E 0002 00165 OPTION
0000 00166 .................... while (1) { //Main polling loop
0000 00167 .................... Freq(); // no code because of inline
0000 00168 .................... BurstLen();
0000 00169 .................... DelaySet();
0000 00170 .................... Ping();
0000 00171 .................... } //while(1)
0078 0A5F 00172 GOTO 05F
0000 00173 .................... } //main()
0000 00174 .................... void Freq() {
0079 0003 00175 SLEEP
0000 00176 .................... key = getch();
005F 090A 00177 CALL 0A // here starts your code
0060 0208 00178 MOVF 08,W
0061 002A 00179 MOVWF 0A // no RET, just continue with the next instr.
0000 00180 .................... } //Freq
0000 00181 .................... void BurstLen(){
0000 00182 .................... key = getch();
0062 090A 00183 CALL 0A
0063 0208 00184 MOVF 08,W
0064 002A 00185 MOVWF 0A
0000 00186 .................... } //BurstLen
0000 00187 .................... void Ping() {
0000 00188 .................... puts("PING");
0004 01E2 00189 ADDWF 02,F
0005 0850 00190 RETLW 50
0006 0849 00191 RETLW 49
0007 084E 00192 RETLW 4E
0008 0847 00193 RETLW 47
0009 0800 00194 RETLW 00
0068 006B 00195 CLRF 0B
0069 020B 00196 MOVF 0B,W
006A 0904 00197 CALL 04
006B 02AB 00198 INCF 0B,F
006C 002C 00199 MOVWF 0C
006D 092E 00200 CALL 2E
006E 0C04 00201 MOVLW 04
006F 008B 00202 SUBWF 0B,W
0070 0743 00203 BTFSS 03,2
0071 0A69 00204 GOTO 069
0072 0C0D 00205 MOVLW 0D
0073 002C 00206 MOVWF 0C
0074 092E 00207 CALL 2E
0075 0C0A 00208 MOVLW 0A
0076 002C 00209 MOVWF 0C
0077 092E 00210 CALL 2E
0000 00211 .................... } //Ping
0000 00212 .................... void DelaySet(){
0000 00213 .................... key = getch();
0065 090A 00214 CALL 0A
0066 0208 00215 MOVF 08,W
0067 002A 00216 MOVWF 0A
0000 00217 .................... } //DelaySet



:=Maybe my brain is fried but I can't see why this code does not generate calls from Main to my functions:
:=
:=#include <16C58A.h>
:=#use delay(clock=20000000)
:=#fuses HS,NOWDT
:=#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B7)
:=
:=char key;
:=
:=void Freq();
:=void DelaySet();
:=void BurstLen();
:=void Ping();
:=
:=void main() {
:=
:=setup_counters(RTCC_INTERNAL,WDT_1152MS);
:=
:=while (1) { //Main polling loop
:= Freq();
:= BurstLen();
:= DelaySet();
:= Ping();
:= } //while(1)
:=} //main()
:=
:=void Freq() {
:= key = getch();
:=} //Freq
:=
:=void BurstLen(){
:= key = getch();
:=} //BurstLen
:=
:=void Ping() {
:= puts("PING");
:=} //Ping
:=
:=void DelaySet(){
:= key = getch();
:=} //DelaySet
:=
:=
:=The code generated for the while loop is:
:=0000 00211 .................... while (1) { //Main polling loop
:=0000 00212 .................... Freq();
:=0000 00213 .................... BurstLen();
:=0000 00214 .................... DelaySet();
:=0000 00215 .................... Ping();
:=0000 00216 .................... } //while(1)
:=007E 0A65 00217 GOTO 065
:=
:=The compiler is PCB ver 3.110
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 13320
Sherpa Doug
Guest







Re: Stupid question - why no function calls
PostPosted: Wed Apr 02, 2003 1:59 pm     Reply with quote

I guess you are right because when I call them twice the function calls are there. I am just confused as to where the goto at the end of the WHILE(1) points to:

:=0000 00171 .................... } //while(1)
:=0078 0A5F 00172 GOTO 05F

Does this line point it itself?

Sherpa Doug

:=Your functions are compiled as inline.
:=Here is the list (different addresses I think):
:=
:=005E 0002 00165 OPTION
:=0000 00166 .................... while (1) { //Main polling loop
:=0000 00167 .................... Freq(); // no code because of inline
:=0000 00168 .................... BurstLen();
:=0000 00169 .................... DelaySet();
:=0000 00170 .................... Ping();
:=0000 00171 .................... } //while(1)
:=0078 0A5F 00172 GOTO 05F
:=0000 00173 .................... } //main()
:=0000 00174 .................... void Freq() {
:=0079 0003 00175 SLEEP
:=0000 00176 .................... key = getch();
:=005F 090A 00177 CALL 0A // here starts your code
:=0060 0208 00178 MOVF 08,W
:=0061 002A 00179 MOVWF 0A // no RET, just continue with the next instr.
:=0000 00180 .................... } //Freq
:=0000 00181 .................... void BurstLen(){
:=0000 00182 .................... key = getch();
:=0062 090A 00183 CALL 0A
:=0063 0208 00184 MOVF 08,W
:=0064 002A 00185 MOVWF 0A
:=0000 00186 .................... } //BurstLen
:=0000 00187 .................... void Ping() {
:=0000 00188 .................... puts("PING");
:=0004 01E2 00189 ADDWF 02,F
:=0005 0850 00190 RETLW 50
:=0006 0849 00191 RETLW 49
:=0007 084E 00192 RETLW 4E
:=0008 0847 00193 RETLW 47
:=0009 0800 00194 RETLW 00
:=0068 006B 00195 CLRF 0B
:=0069 020B 00196 MOVF 0B,W
:=006A 0904 00197 CALL 04
:=006B 02AB 00198 INCF 0B,F
:=006C 002C 00199 MOVWF 0C
:=006D 092E 00200 CALL 2E
:=006E 0C04 00201 MOVLW 04
:=006F 008B 00202 SUBWF 0B,W
:=0070 0743 00203 BTFSS 03,2
:=0071 0A69 00204 GOTO 069
:=0072 0C0D 00205 MOVLW 0D
:=0073 002C 00206 MOVWF 0C
:=0074 092E 00207 CALL 2E
:=0075 0C0A 00208 MOVLW 0A
:=0076 002C 00209 MOVWF 0C
:=0077 092E 00210 CALL 2E
:=0000 00211 .................... } //Ping
:=0000 00212 .................... void DelaySet(){
:=0000 00213 .................... key = getch();
:=0065 090A 00214 CALL 0A
:=0066 0208 00215 MOVF 08,W
:=0067 002A 00216 MOVWF 0A
:=0000 00217 .................... } //DelaySet
:=
:=
:=
:=:=Maybe my brain is fried but I can't see why this code does not generate calls from Main to my functions:
:=:=
:=:=#include <16C58A.h>
:=:=#use delay(clock=20000000)
:=:=#fuses HS,NOWDT
:=:=#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B7)
:=:=
:=:=char key;
:=:=
:=:=void Freq();
:=:=void DelaySet();
:=:=void BurstLen();
:=:=void Ping();
:=:=
:=:=void main() {
:=:=
:=:=setup_counters(RTCC_INTERNAL,WDT_1152MS);
:=:=
:=:=while (1) { //Main polling loop
:=:= Freq();
:=:= BurstLen();
:=:= DelaySet();
:=:= Ping();
:=:= } //while(1)
:=:=} //main()
:=:=
:=:=void Freq() {
:=:= key = getch();
:=:=} //Freq
:=:=
:=:=void BurstLen(){
:=:= key = getch();
:=:=} //BurstLen
:=:=
:=:=void Ping() {
:=:= puts("PING");
:=:=} //Ping
:=:=
:=:=void DelaySet(){
:=:= key = getch();
:=:=} //DelaySet
:=:=
:=:=
:=:=The code generated for the while loop is:
:=:=0000 00211 .................... while (1) { //Main polling loop
:=:=0000 00212 .................... Freq();
:=:=0000 00213 .................... BurstLen();
:=:=0000 00214 .................... DelaySet();
:=:=0000 00215 .................... Ping();
:=:=0000 00216 .................... } //while(1)
:=:=007E 0A65 00217 GOTO 065
:=:=
:=:=The compiler is PCB ver 3.110
:=:=
:=:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 13325
Tomi
Guest







Re: Stupid question - why no function calls
PostPosted: Thu Apr 03, 2003 1:31 am     Reply with quote

Your PIC has only 2-deep stack (and one level is reserved for serial functions Smile ) so CCS tries to keep the calling tree as simple as possible. You can see a nice zig-zag in the list:
-the first code at "} //while" is the _last_ instruction of the loop: goto LoopBegin; this lays @0x078.
-the loop begins @0x51 (@0x50 is the OPTION instruction)
-but at this address is the "key = getch" as the 1st instr. of "Freq()"
-the code continues with next getch in BurstLen, etc.
-your next call is Ping what is composed as a table placed to 0x04 address and a call to the table from 0x68.

All in all, your original code is translated as:
loop:
key = getch(); //from Freq
key = getch(); //from BurstLen
key = getch(); // from DelaySet
puts("PING"); // from Ping, the table read is placed just before puts()
goto loop;

IMHO if you want to call your functions more than once then you have to check "stack locations" in your list file after every new compilation.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13342
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group