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

Problems with MPASM & C

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



Joined: 25 Sep 2003
Posts: 4

View user's profile Send private message

Problems with MPASM & C
PostPosted: Thu Dec 18, 2003 3:08 am     Reply with quote

Hi folks,

Have been using CCS C for approx 2 months. Now I need to put some assembler in and cannot compile the code !
Could someone give me an idea as to what I'm doing wrong ?

I'm Using :
MPLAB v6.32
Microchip ICD2 with PICDEM 2 plus board
PIC18F452 chip installed
CCS PCWH C compiler v3.179,
All running under Windows XP professional (service pack 1) on an Athlon 1500+ PC with 320Mb ram.

This is an example of what I cannot compile. I get "Expecting an opcode mnemonic" error.

Code:
/* ASMTest.c
Test for including MPASM assembler code in CCS C */
#include <18f452.h>
#fuses NOWDT,NOPROTECT,NOLVP,NOWRT,NOEBTR
#DEVICE ICD=TRUE
#use delay (clock=4000000)

// Declare three 8 bit integers
int count;
int count2;
int result;

// Put them at RAM locations 0x420 to 0x422
#byte count=0x420
#byte count2=0x421
#byte result=0x422

void main(void)
{ count=1;
  count2=2;
   
#ASM
  // Move 4 into BSR to access Bank 4
  MOVLB 4
  // Move contents of 0x420 into WREG (1)
  MOVF 0x20, 0, 1
  // Add WREG to contents of 0x421 (2), store result (3) in WREG,
  ADDWF 0x21, 0, 1
  // Copy WREG to 0x422
  MOVWF 0x22,1
#ENDASM
}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Dec 18, 2003 9:25 am     Reply with quote

CCS doesn't like the RAM access bit. Try this

Code:

/* ASMTest.c
Test for including MPASM assembler code in CCS C */
#include <18f452.h>
#fuses NOWDT,NOPROTECT,NOLVP,NOWRT,NOEBTR
#DEVICE ICD=TRUE
#use delay (clock=4000000)

// Declare three 8 bit integers
int count;
int count2;
int result;

// Put them at RAM locations 0x420 to 0x422
#byte count=0x420
#byte count2=0x421
#byte result=0x422

void main(void)
{ count=1;
  count2=2;
   
#ASM
  // Move 4 into BSR to access Bank 4
  MOVLB 4
  // Move contents of 0x420 into WREG (1)
  MOVF 0x20, 0
  // Add WREG to contents of 0x421 (2), store result (3) in WREG,
  ADDWF 0x21, 0
  // Copy WREG to 0x422
  MOVWF 0x22
#ENDASM
}
Nigel



Joined: 25 Sep 2003
Posts: 4

View user's profile Send private message

Thanks Mark
PostPosted: Thu Dec 18, 2003 9:42 am     Reply with quote

Thanks for your help, that's fixed it !
Ttelmah
Guest







Re: Thanks Mark
PostPosted: Thu Dec 18, 2003 10:02 am     Reply with quote

Nigel wrote:
Thanks for your help, that's fixed it !


Worth adding, that you don't actually have to do the bank switching!.
You can code as:

#ASM
// Move contents of 0x420 into WREG (1)
MOVF count, 0
// Add WREG to contents of 0x421 (2), store result (3) in WREG,
ADDWF count2, 0
// Copy WREG to 0x422
MOVWF result
#ENDASM

The compiler supports, a sort of 'C hybrid' compiler syntax, and will automatically bank switch for you, if you use the symbolic names (in the example as given the compiler will not actually code a bank switch, since bank 4 is allready selected to initialise the variables). If you don't want this 'auto switching' to take place, add 'asis', to the #ASM directive.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Dec 18, 2003 10:57 am     Reply with quote

One more thing, if you do use the variable name and the variable is bigger than 8 bits, the syntax is

&counter+1

and not

counter+1
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