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

Multiply/Divide Problems ccs 3.124

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







Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 10:58 am     Reply with quote

Having trouble using multiply and divide on ccs 3.124 with pic16f876 (MPLAB 5.7). The object code that is generated is missing the multiply and divide stubs.

here's sample code:


#include <16F876.H>

main ()
{
int a;
int b;

a = 1200;
b = 12*a;
}
generates:

CCS PCM C Compiler, Version 3.124, 16648

Filename: C:\BK\KEYERS\K45C\TEST.LST

ROM used: 60 (1\%)
Largest free fragment is 2048
RAM used: 7 (4\%) at main() level
9 (5\%) worst case
Stack: 1 locations

*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 02B
0003: NOP
....................
.................... #include <16F876.H>
.................... //////// Standard Header file for the PIC16F876 device ////////////////
.................... #device PIC16F876
.................... #list
....................
....................
.................... main ()
.................... {
.................... int a;
.................... int b;
002B: CLRF 04
002C: MOVLW 1F
002D: ANDWF 03,F
002E: MOVLW 07
002F: BSF 03.5
0030: MOVWF 1F
0031: BCF 03.5
....................
.................... a = 1200;
0032: MOVLW B0
0033: MOVWF 21
.................... b = 12*a;
0034: MOVLW 0C
0035: MOVWF 23
0036: MOVF 21,W
0037: MOVWF 24
0038: GOTO 004
0039: MOVF 78,W
003A: MOVWF 22
.................... }
....................
003B: SLEEP
....................

***

That is all the code that gets generated.

Notice that there is a jump to the multiply handler at address 004 but there is nothing present at 004, it wasn't included by the complier !!
Am I missing an include file ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514786
davidpk
Guest







Re: Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 11:14 am     Reply with quote

An int variable is limited to 0-255, both 1200 and 12*1200 are too large for the variables. Try the 'long' variable type.

:=Having trouble using multiply and divide on ccs 3.124 with pic16f876 (MPLAB 5.7). The object code that is generated is missing the multiply and divide stubs.
:=
:=here's sample code:
:=
:=
:=#include <16F876.H>
:=
:=main ()
:={
:= int a;
:= int b;
:=
:= a = 1200;
:= b = 12*a;
:=}
:=generates:
:=
:=CCS PCM C Compiler, Version 3.124, 16648
:=
:= Filename: C:\BK\KEYERS\K45C\TEST.LST
:=
:= ROM used: 60 (1\%)
:= Largest free fragment is 2048
:= RAM used: 7 (4\%) at main() level
:= 9 (5\%) worst case
:= Stack: 1 locations
:=
:=*
:=0000: MOVLW 00
:=0001: MOVWF 0A
:=0002: GOTO 02B
:=0003: NOP
:=....................
:=.................... #include <16F876.H>
:=.................... //////// Standard Header file for the PIC16F876 device ////////////////
:=.................... #device PIC16F876
:=.................... #list
:=....................
:=....................
:=.................... main ()
:=.................... {
:=.................... int a;
:=.................... int b;
:=002B: CLRF 04
:=002C: MOVLW 1F
:=002D: ANDWF 03,F
:=002E: MOVLW 07
:=002F: BSF 03.5
:=0030: MOVWF 1F
:=0031: BCF 03.5
:=....................
:=.................... a = 1200;
:=0032: MOVLW B0
:=0033: MOVWF 21
:=.................... b = 12*a;
:=0034: MOVLW 0C
:=0035: MOVWF 23
:=0036: MOVF 21,W
:=0037: MOVWF 24
:=0038: GOTO 004
:=0039: MOVF 78,W
:=003A: MOVWF 22
:=.................... }
:=....................
:=003B: SLEEP
:=....................
:=
:=***
:=
:=That is all the code that gets generated.
:=
:=Notice that there is a jump to the multiply handler at address 004 but there is nothing present at 004, it wasn't included by the complier !!
:=Am I missing an include file ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514787
Steve Elliott
Guest







Re: Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 12:33 pm     Reply with quote

:=An int variable is limited to 0-255, both 1200 and 12*1200 are too large for the variables. Try the 'long' variable type.
:=

hmmm.... same thing...


#include <16F876.H>

main ()
{
long a;
long b;

a = 1200;
b = 12*a;
}

generates:
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 01B
0003: NOP
....................
.................... #include <16F876.H>
.................... //////// Standard Header file for the PIC16F876 device ////////////////
.................... #device PIC16F876
.................... #list
....................
....................
.................... main ()
.................... {
.................... long a;
.................... long b;
001B: CLRF 04
001C: MOVLW 1F
001D: ANDWF 03,F
001E: MOVLW 07
001F: BSF 03.5
0020: MOVWF 1F
0021: BCF 03.5
....................
.................... a = 1200;
0022: MOVLW 04
0023: MOVWF 22
0024: MOVLW B0
0025: MOVWF 21
.................... b = 12*a;
0026: CLRF 26
0027: MOVLW 0C
0028: MOVWF 25
0029: MOVF 22,W
002A: MOVWF 28
002B: MOVF 21,W
002C: MOVWF 27
002D: GOTO 004
002E: MOVF 79,W
002F: MOVWF 24
0030: MOVF 78,W
0031: MOVWF 23
.................... }
....................
0032: SLEEP
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514788
Steve Elliott
Guest







Re: Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 1:46 pm     Reply with quote

Ok, sorry for the bandwidth, the code is there in the hex file it is just not included in the MPLAB .lst file. It is odd to step through the code and see it get frozen on the goto line while it is executing code "that isn't there". But is does come back magically with the correct calculated value.

I'm guessing it's protected code, hidden to protect IP ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514790
R.J.Hamlett
Guest







Re: Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 1:47 pm     Reply with quote

:=Having trouble using multiply and divide on ccs 3.124 with pic16f876 (MPLAB 5.7). The object code that is generated is missing the multiply and divide stubs.
:=
:=here's sample code:
:=
:=
:=#include <16F876.H>
:=
:=main ()
:={
:= int a;
:= int b;
:=
:= a = 1200;
:= b = 12*a;
:=}
:=generates:
:=
:=CCS PCM C Compiler, Version 3.124, 16648
:=
:= Filename: C:\BK\KEYERS\K45C\TEST.LST
:=
:= ROM used: 60 (1\%)
:= Largest free fragment is 2048
:= RAM used: 7 (4\%) at main() level
:= 9 (5\%) worst case
:= Stack: 1 locations
:=
:=*
:=0000: MOVLW 00
:=0001: MOVWF 0A
:=0002: GOTO 02B
:=0003: NOP
:=....................
:=.................... #include <16F876.H>
:=.................... //////// Standard Header file for the PIC16F876 device ////////////////
:=.................... #device PIC16F876
:=.................... #list
:=....................
:=....................
:=.................... main ()
:=.................... {
:=.................... int a;
:=.................... int b;
:=002B: CLRF 04
:=002C: MOVLW 1F
:=002D: ANDWF 03,F
:=002E: MOVLW 07
:=002F: BSF 03.5
:=0030: MOVWF 1F
:=0031: BCF 03.5
:=....................
:=.................... a = 1200;
:=0032: MOVLW B0
:=0033: MOVWF 21
:=.................... b = 12*a;
:=0034: MOVLW 0C
:=0035: MOVWF 23
:=0036: MOVF 21,W
:=0037: MOVWF 24
:=0038: GOTO 004
:=0039: MOVF 78,W
:=003A: MOVWF 22
:=.................... }
:=....................
:=003B: SLEEP
:=....................
:=
:=***
:=
:=That is all the code that gets generated.
:=
:=Notice that there is a jump to the multiply handler at address 004 but there is nothing present at 004, it wasn't included by the complier !!
:=Am I missing an include file ?
There is nothing wrong with the code...
The compiler does not generate assembler, in the list file for these routines, by default. The code is sitting there, between 0004, and 002B. If you look at the hex file, or import it into MPLAB, you will see the code is there.
If you want to see it, edit the start of the 16F876.h file, and change the third line (which normally reads #nolist), and remark this out as //#nolist). Recompile, and the code will be displayed.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514791
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Multiply/Divide Problems ccs 3.124
PostPosted: Tue May 27, 2003 2:11 pm     Reply with quote

:=Ok, sorry for the bandwidth, the code is there in the hex file it is just not included in the MPLAB .lst file. It is odd to step through the code and see it get frozen on the goto line while it is executing code "that isn't there". But is does come back magically with the correct calculated value.
----------------------------------------------------

You can see the code if you go to the Window/Program Memory
menu in MPLAB.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514792
Michael Thompson
Guest







Re: Multiply/Divide Problems ccs 3.124
PostPosted: Wed May 28, 2003 8:35 am     Reply with quote

:=Having trouble using multiply and divide on ccs 3.124 with pic16f876 (MPLAB 5.7). The object code that is generated is missing the multiply and divide stubs.
:=
:=here's sample code:
:=
:=
:=#include <16F876.H>
:=
:=main ()
:={
:= int a;
:= int b;
:=
:= a = 1200;
:= b = 12*a;
:=}
:=generates:
:=
:=CCS PCM C Compiler, Version 3.124, 16648
:=
:= Filename: C:\BK\KEYERS\K45C\TEST.LST
:=
:= ROM used: 60 (1\%)
:= Largest free fragment is 2048
:= RAM used: 7 (4\%) at main() level
:= 9 (5\%) worst case
:= Stack: 1 locations
:=
:=*
:=0000: MOVLW 00
:=0001: MOVWF 0A
:=0002: GOTO 02B
:=0003: NOP
:=....................
:=.................... #include <16F876.H>
:=.................... //////// Standard Header file for the PIC16F876 device ////////////////
:=.................... #device PIC16F876
:=.................... #list
:=....................
:=....................
:=.................... main ()
:=.................... {
:=.................... int a;
:=.................... int b;
:=002B: CLRF 04
:=002C: MOVLW 1F
:=002D: ANDWF 03,F
:=002E: MOVLW 07
:=002F: BSF 03.5
:=0030: MOVWF 1F
:=0031: BCF 03.5
:=....................
:=.................... a = 1200;
:=0032: MOVLW B0
:=0033: MOVWF 21
:=.................... b = 12*a;
:=0034: MOVLW 0C
:=0035: MOVWF 23
:=0036: MOVF 21,W
:=0037: MOVWF 24
:=0038: GOTO 004
:=0039: MOVF 78,W
:=003A: MOVWF 22
:=.................... }
:=....................
:=003B: SLEEP
:=....................
:=
:=***
:=
:=That is all the code that gets generated.
:=
:=Notice that there is a jump to the multiply handler at address 004 but there is nothing present at 004, it wasn't included by the complier !!
:=Am I missing an include file ?

R.J. is correct in that the code for the multiply routine at 004 will only be in the list file if the #nolist in the pic16f876.h file is commented out or removed.

Try a = 1200L; to ensure that the constant is typed to that of a long.

Regards,
Mike
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514812
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