Searching \ for '[PIC]:18x C compiler questions' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: '18x C compiler questions'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:18x C compiler questions'
2000\12\11@071017 by info

flavicon
face
Hi list
I have just downloaded the demo version of microchip C18 because my ASM
projects are spiralling in size and i think now is the time to switch to
C.
For my money what is the best C compiler on the market? How does the
microchip one shape up. It would be nice if it had at least few demo
programs.

By the way. What does reentrancy mean? as in: (Global variables require
less code to access at the expense of data memory and reentrancy.)

Best regards
Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@072053 by Bond Peter S-petbond1

flavicon
face
Scott -

> By the way. What does reentrancy mean? as in: (Global
> variables require
> less code to access at the expense of data memory and reentrancy.)

Re-entrant

<programming> Used to describe code which can have multiple simultaneous,
interleaved, or nested invocations which will not interfere with each other.
This is important for parallel processing, recursive functions or
subroutines, and interrupt handling.

It is usually easy to arrange for multiple invocations (e.g. calls to a
subroutine) to share one copy of the code and any read-only data but, for
the code to be re-entrant, each invocation must use its own copy of any
modifiable data (or synchronised access to shared data). This is most often
achieved using a stack and allocating local variables in a new stack frame
for each invocation. Alternatively, the caller may pass in a pointer to a
block of memory which that invocation can use (usually for outputting the
result) or the code may allocate some memory on a heap, especially if the
data must survive after the routine returns.

Re-entrant code is often found in system software, such as operating systems
and teleprocessing monitors. It is also a crucial component of multithreaded
programs where the term "thread-safe" is often used instead of "re-entrant".

source http://www.foldoc.org

In practical terms, if your code needs to be re-entrant, don't use globals
and don't allocate any variables within the function as static.

HTH

Peter

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@081923 by Bob Ammerman

picon face
> > By the way. What does reentrancy mean? as in: (Global
> > variables require
> > less code to access at the expense of data memory and reentrancy.)

A quick explanation of how this might be implemented on an 18C chip.

A global variable is simple a memory location, allocated by the
compiler/linker, used to hold the value. The value is always in the same
location. If the variable is allocated to access RAM it can always be
accessed in a single cycle like this:

   movf    global_var,w,a

   addwf    global_var,f,a

etc.

Very efficient.

If the variable is not in access RAM you can still get at it with a two
cycle/two word instruction:

   movff    global_var,someplace

   movff    someplace,global_var

Local variables get a little more complicated on a PIC. In the traditional
implementation, the compiler/linker figure out what functions call what
functions and they allocate variables to memory locations in such a way that
a location is never reused for another purpose while its function is active.
This is good (because access to the variable is as efficient as accessing a
global), but it doesn't allow the functions to be called recursively or
reentrantly (e.g. from an interrupt handler and main-line code at the same
time).

On the 18C you can create a real 'stack' of variables. Now a function that
needs local variables can keep them on the stack, probably pointed to by an
FSR. The 18C has a neat 'indexed with offset' access mode that can be
efficient to read them. Given that FSR2 points to the 'stack frame', and
that the desired value is at offset 'my_var' relative to FSR2, the following
will access the local variable:

   movlw    my_var               ; offset of variable
   movf      PLUSW2,W,A   ; get the variable at [FSR2+W]

You do have to deal with the overhead of managing FSR2 of course.

Note that in "C" you can have a variable that is local to a function, yet is
allocated like a global. This is done with the static keyword:

void foo()
{
   unsigned char bar;    // dynamically (stack) allocated
   static unsigned char baz;    // statically allocated
}

'bar' will have an indeterminate value on each entry to foo(), 'baz' will
retain its value from one call to the next.

Real 'C' would allow foo() to be recursive and reentrant, each
recursive/reentrant call would create a new 'bar' but use the same 'baz'.

PIC compilers have traditionally generally not supported recursive/reentrant
code, but the 18C does a pretty good job of it. I do not know if MPLAB-C18
uses a stack for local's, but I would guess that they do.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)







> Re-entrant
>
> <programming> Used to describe code which can have multiple simultaneous,
> interleaved, or nested invocations which will not interfere with each
other.
> This is important for parallel processing, recursive functions or
> subroutines, and interrupt handling.
>
> It is usually easy to arrange for multiple invocations (e.g. calls to a
> subroutine) to share one copy of the code and any read-only data but, for
> the code to be re-entrant, each invocation must use its own copy of any
> modifiable data (or synchronised access to shared data). This is most
often
> achieved using a stack and allocating local variables in a new stack frame
> for each invocation. Alternatively, the caller may pass in a pointer to a
> block of memory which that invocation can use (usually for outputting the
> result) or the code may allocate some memory on a heap, especially if the
> data must survive after the routine returns.
>
> Re-entrant code is often found in system software, such as operating
systems
> and teleprocessing monitors. It is also a crucial component of
multithreaded
> programs where the term "thread-safe" is often used instead of
"re-entrant".
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@100851 by Olin Lathrop

face picon face
> By the way. What does reentrancy mean? as in: (Global variables require
> less code to access at the expense of data memory and reentrancy.)

Are you sure you want to be writing embedded code for small controllers in
C?  There are times when this may be appropriate, but you have to be much
more aware of what the compiler is doing on your behalf than when writing C
for running on a high level operating system.  This requires a good grasp of
basic concepts like stack frames, re-entrancy, subroutine linkage, etc.

I don't want to repeat all of Comp Sci 101 here, so this is just a brief
overview.  You need to look up and study this stuff else you will get into
trouble writing PIC code in C.

There are two broad classes of how memory (variables) can be allocated,
static and dynamic (I'm using descriptive words here, not necessarily C
syntax).  The address of a static variable is determined before the program
is executed.  A static variable therefore lives at a known address, and is
"permanent" from the point of view of the program.  Dynamic memory is
allocated and deallocated as desired.  Variables that are local to a
subroutine are usually allocated dynamically by leaving extra room for them
in the stack frame for that subroutine invocation.  This means that each
invocation of the subroutine gets a "fresh" copy of the variable which
starts out with an unknown value.  This becomes important, for example, when
a subroutine calls itself recursively.  Each recursive invocation of the
subroutine has its own copy of local dynamically allocated variables, but
all invocations will see the single copy of a statically allocated variable.

In general, less data memory is used if variables are allocated dynamically
only when needed.  This is because in most cases all possible variables are
not needed at the same time.  The drawback is that dynamically allocating
and deallocating variables takes code and cycles, and often some extra
memory to keep track of where memory has been allocated and where it's still
available.

Re-entrant routines are those that can be called more than once
concurrently.  Recursion is one example of re-entrancy.  Often re-entrant
routines will require some state that is unique to each invocation.  Most
compilers support this by dynamically allocating the variable at call time
on the stack frame.  This is what a C "automatic" variable is.

A "global" symbol is one that can be visible in modules other than the one
it is defined in.  Since the address of a global variable is assumed to be
constant by all modules in the system, global variables are statically
allocated.  The sentence you quoted above used "global" when it was really
referring to "static".  C tends to blur this distinction also.  Global
implies static, but you can have static variables that are not global.

Good code intended for high level operating systems tends to make state
dynamic except for that state which needs to be global.  This is because the
operating system has good facilities for dynamic memory management and the
processor usually has instructions to help maintain stack frames and access
memory within stack frames.

Good PIC code tends to make variables static unless there is a reason not
to.  Except for the 18xxx PICs, you can't even get at the call stack and
there are no PUSH/POP instructions to directly support a data stack.  The
nature of embedded applications (perform a well defined task in a rock solid
manner in real time) also tends away from the kind of code that would want
to use dynamic memory.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, EraseMEolinspam_OUTspamTakeThisOuTembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@101951 by info

flavicon
face
Can anyone help on how to use the strlen function in c18
This is all all a little new to me so go easy.
I have a table (string) in ROM that I want to compute the length of.
I have read the microchip data on the function but don't quite
understand how to implement it.


can anyone correct this. Thanks in advance!

#include <p18c452.h>
#include <adc.h>
#include <string.h>
void main(void);
size_t strlen (const char * str);
unsigned char x, y, z;
rom char name[]="here is my string";

void main()
{
y=strlen(const char *name);
for (x=1; x<y; x++)
z=name[x];
}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@102201 by Andrew Kunz

flavicon
face
>Are you sure you want to be writing embedded code for small controllers in
>C?  There are times when this may be appropriate...

Yup, like "Almost all the time."

When you are not paid by the hour (FFP vs T&M), it is much more profitable
besides making better and more manageable code.

Andy

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@110302 by info

flavicon
face
In message <RemoveME852569B2.005491AA.00TakeThisOuTspamtdipower.com>, Andrew Kunz
<spamBeGoneakunzspamBeGonespamTDIPOWER.COM> writes
>>Are you sure you want to be writing embedded code for small controllers in
>>C?  There are times when this may be appropriate...
>
>Yup, like "Almost all the time."
>
>When you are not paid by the hour (FFP vs T&M), it is much more profitable
>besides making better and more manageable code.
>
>Andy



Are there any lists or forums that are aimed at 18 series and are C
based?
Scott

Still waiting for reply's about your favourite 18 series C compilers {;




>
>--
>http://www.piclist.com#nomail Going offline? Don't AutoReply us!
>email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@112104 by Michael Rigby-Jones

flavicon
face
> -----Original Message-----
> From: Andrew Kunz [SMTP:akunzEraseMEspam.....TDIPOWER.COM]
> Sent: Monday, December 11, 2000 3:24 PM
> To:   EraseMEPICLISTspamMITVMA.MIT.EDU
> Subject:      Re: [PIC]:18x C compiler questions
>
> >Are you sure you want to be writing embedded code for small controllers
> in
> >C?  There are times when this may be appropriate...
>
> Yup, like "Almost all the time."
>
> When you are not paid by the hour (FFP vs T&M), it is much more profitable
> besides making better and more manageable code.
>
> Andy
>
>
Absolutely, especialy if your code has a lot of 16/32 operations then C
makes code maintenance a whole lot easier.

If you are costing parts down to the last cent, then using a smaller/slower
part and coding in ASM might save some money, but the difference in code
size between C and ASM, at least on the midrange parts, is generaly pretty
small.

Mike

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@113738 by M. Adam Davis

flavicon
face
There may be at http://www.microchip.com/

info wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservSTOPspamspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@114738 by M. Adam Davis

flavicon
face
info wrote:
>
> Hi list
> I have just downloaded the demo version of microchip C18 because my ASM
> projects are spiralling in size and i think now is the time to switch to
> C.

Sounds like a good reason to switch to C...

> For my money what is the best C compiler on the market?

I don't know, tell me about your money.  For my money (ie, none) the best
compiler I've found is CC5X, which supports programs up to 1K words.  For
my Boss's money, CCS is good.  We'll be receiving it in a few days, and I
write up a comparison between the two.

Of course, neither of these support the 18C series of uC.  You might try
hi tech.  Most of the compilers out now do not support the 18C, but should
shortly.

> How does the
> microchip one shape up. It would be nice if it had at least few demo
> programs.

Nearly all of the newer app notes at http://www.microchip.com use the C
versions they sell, and most are compatible across the entire line.  (ie,
get the 16C or 17C app note, and you can compile that code in the 18c
compiler with few changes)

> By the way. What does reentrancy mean?

A reentrant function is one which might not return before being called
again.  ie, it could be recursive, or it (A) could call another function
(B) which might call it (A).

> as in: (Global variables require
> less code to access at the expense of data memory and reentrancy.)

Using a global variable in a function makes it 'static', it's value does
not change from function call to function call, and if the function has
been called again (B) when call (A) hasn't returned, then B will affect
the global variable, which would affect how A operates when B returns.

-Adam

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspamspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@120430 by Olin Lathrop

face picon face
Andrew Kunz wrote:
> Yup, like "Almost all the time."
>
> When you are not paid by the hour (FFP vs T&M), it is much more profitable
> besides making better and more manageable code.

Let's not get into this pissing contest, as this has been done many times
before.  I therefore won't respond with specific arguments, but I don't want
newbies listening in to think that your blanket statements are generally
accepted facts.  There is a lot more to this issue, as I think you know.
Implying that the only reason to use assembler is to run up billable time
is untrue, irresponsible, and frankly assinine.

The point I originally made had nothing to do with assembler being better or
worse than C, only that it is particularly important to understand what the
compiler - if you chose to use one - is doing on your behalf on a small
resource-limited system.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, KILLspamolinspamBeGonespamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body


2000\12\11@120836 by Andy Jancura

picon face
>Are there any lists or forums that are aimed at 18 series and are C
>based?
>Scott
>
>Still waiting for reply's about your favourite 18 series C compilers {;
>

Hi Scott,

I didn't see any specialized forum on 18C, but will be very interested in
this too. There are some times questions on the piclist, where you can find
some solutions for problems.

The compilers for 18C I know just a few.

First isn't a really C but is free and done by someone in the list.
Then Microchip 18C, IAR and HiTech. I would like to test IAR and HiTech, but
HiTech hasn't at the moment a demo of their PICC18 on web. What was written
in this list, I guess that the PICC18 from HiTech is just a PICC ported to
18C, there will not be too much and good optimization for 18C now.

Andrej

_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listserv@spam@spamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...