  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			Nigel
 
 
  Joined: 25 Sep 2003 Posts: 4
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Problems with MPASM & C | 
			 
			
				 Posted: Thu Dec 18, 2003 3:08 am     | 
				     | 
			 
			
				
  | 
			 
			
				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 
			
			 
			 
			 
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 18, 2003 9:25 am     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Thanks Mark | 
			 
			
				 Posted: Thu Dec 18, 2003 9:42 am     | 
				     | 
			 
			
				
  | 
			 
			
				| Thanks for your help, that's fixed it ! | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Ttelmah Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: Thanks Mark | 
			 
			
				 Posted: Thu Dec 18, 2003 10:02 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | 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 
			
			 
			 
			 
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 18, 2003 10:57 am     | 
				     | 
			 
			
				
  | 
			 
			
				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 | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
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
  
		 |