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 CCS Technical Support

Using Assembly Code in CCS C

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



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

Using Assembly Code in CCS C
PostPosted: Thu Jun 30, 2005 3:10 pm     Reply with quote

In CCS C, I can include a library (for example LCD.C) to be used by my main code.

Is it possible to use a Assembly Code library in CCS C?
How do I #inlcude it?
How would I know what prototype to use in my C code?

Assembly code has only registers and "W", not char, byte, int, etc.

Any example would be great.

Thankx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 30, 2005 3:19 pm     Reply with quote

The following CCS files have examples of inline ASM code.
These files come with your compiler and are in the folders shown below.
c:\program files\picc\examples\ex_glint.c
c:\program files\picc\examples\ex_bootloader.c
c:\program files\picc\drivers\bootloader.c
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 30, 2005 3:24 pm     Reply with quote

I've seen inline code for asm.

I'm not sure how to use a library (lib.asm).
Usually in asm codes, a value is put on "W" register and then used throughout the code. How would I use it in CCS C?

what is the W register in CCS C?
Ttelmah
Guest







PostPosted: Thu Jun 30, 2005 3:30 pm     Reply with quote

CCS C, supports it's own assembler 'format', which is a sort of compromise between C, and assembler. You cannot by any easy method incorporate external assembler (you can but it is hard work...). The easiest way to use assembler in CCS, is to embed it in the C itself. So (for instance), you can use:
Code:

int8 silly_increment(int8 value) {
   int8 local;
#asm
   incf value,W
   movwf local
#endasm
   //At this point the value that was in 'value', has been incremented
   //by one, and transferred to the variable 'local'
   if (value>100) return(0);
   else return(local);
}
//Now I show 'C' being used to test the result, and return a value

Basically, the assembler used in CCS, supports 'C' syntax for the variables themselves, and standard assembler syntax for the operations.
In the thread 'interrupting an interrupt', I posted an assembler routine, showing the way the syntax works (you have to declare the internal function registers with the #byte, and #bit statements to use this).
You then load the assembler in this form, and let CCS compile it.
CCS has no support for precompiled (or pre-assembled) libraries.

Best Wishes
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

PostPosted: Thu Jun 30, 2005 3:50 pm     Reply with quote

would you please point me to your thread? (Interrupting an interrupt)

I cannot search for it.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Jun 30, 2005 3:57 pm     Reply with quote

Sure you can!!!

Use the search feature (at the top of the page) and put in "interrupting an interrupt" (without the quotes) and it will be the second item in the list.
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