View previous topic :: View next topic |
Author |
Message |
jahan
Joined: 04 Apr 2005 Posts: 63
|
Using Assembly Code in CCS C |
Posted: Thu Jun 30, 2005 3:10 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 30, 2005 3:19 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
jahan
Joined: 04 Apr 2005 Posts: 63
|
|
Posted: Thu Jun 30, 2005 3:24 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Jun 30, 2005 3:30 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
jahan
Joined: 04 Apr 2005 Posts: 63
|
|
Posted: Thu Jun 30, 2005 3:50 pm |
|
|
would you please point me to your thread? (Interrupting an interrupt)
I cannot search for it. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Thu Jun 30, 2005 3:57 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|