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

in multi line macros

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



Joined: 09 Sep 2003
Posts: 67
Location: Winterthur, Switzerland

View user's profile Send private message

in multi line macros
PostPosted: Wed Nov 14, 2001 3:52 pm     Reply with quote

Hello

If I try the following...

#any define...\
#asm\
movlw 0x00\ // any hex value
movwf 0x00\ // any register
#endasm\

..I receive an error (Expecting an opcode mnemonic).

If I change it to the following...

#any define...\
#asm\
movlw 0x00\ // any hex value
#endasm\
#asm\
movwf 0x00\ // any register
#endasm\
...everything works ok.

Any ideas why? Or did I miss something important?

Thanks
mfg
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 1106
Charlie U
Guest







Re: in multi line macros
PostPosted: Wed Nov 14, 2001 4:46 pm     Reply with quote

:=Hello
:=
:=If I try the following...
:=
:=#any define...\
:=#asm\
:=movlw 0x00\ // any hex value
:=movwf 0x00\ // any register
:=#endasm\
:=
:=..I receive an error (Expecting an opcode mnemonic).
:=
:=If I change it to the following...
:=
:=#any define...\
:=#asm\
:=movlw 0x00\ // any hex value
:=#endasm\
:=#asm\
:=movwf 0x00\ // any register
:=#endasm\
:=...everything works ok.
:=
:=Any ideas why? Or did I miss something important?
:=
:=Thanks
:=mfg
:=Felix

Felix . . .

The backslash character at the end of a line is a "line splicing" character. Refer to K&R 2nd edition, section A12.2. The compiler attempts to delete the \ and the following new line character before interpreting the lines. I'm guessing that the compiler is getting confused by the \'s at the ends. In any case, why are you putting the \ at the end of all of the lines anyway?? I'm just a relatively new c programmer, but I've never seen this before.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1108
Felix Althaus



Joined: 09 Sep 2003
Posts: 67
Location: Winterthur, Switzerland

View user's profile Send private message

Re: in multi line macros
PostPosted: Wed Nov 14, 2001 5:11 pm     Reply with quote

:=I'm guessing that the compiler is getting confused by the \'s :=at the ends. In any case, why are you putting the \ at the :=end of all of the lines anyway?? I'm just a relatively new c :=programmer, but I've never seen this before.

If you mean, I should put the \ at the beginning of each line, it doesn't work (I tested it).

Any other suggestions?

Thanks
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 1109
Charlie U
Guest







Re: in multi line macros
PostPosted: Wed Nov 14, 2001 9:21 pm     Reply with quote

:=:=I'm guessing that the compiler is getting confused by the \'s :=at the ends. In any case, why are you putting the \ at the :=end of all of the lines anyway?? I'm just a relatively new c :=programmer, but I've never seen this before.
:=
:=If you mean, I should put the \ at the beginning of each line, it doesn't work (I tested it).
:=
:=Any other suggestions?
:=
:=Thanks
:=Felix

Felix,

I just don't know what the \ is needed for. I must plead ignorance of macros, but for inline assembly code, which your first post appeared to be about, the \'s are not required. I can't find any reference to backslashes and macros anywhere. What exactly are you trying to achieve with the backslashes??
___________________________
This message was ported from CCS's old forum
Original Post ID: 1114
Tomi
Guest







Re: in multi line macros
PostPosted: Thu Nov 15, 2001 2:39 am     Reply with quote

<font face="Courier New" size=-1>Just a small confuse about "\".
The #asm directive is NOT a macro.
Some definitions MUST be in one unbreaked line, e.g. "#define name solution". For a better read, C standard has the "\" definition what means the following: "forget the line terminating character and concatenate lines".
But the #asm directive means:
"compile the lines below as assembler instructions TIL the #endasm directive." Legal usage of asm directive:
#asm // newline
instr1 // newline
instr2 // newline
.......// newline
#endasm // newline

In your case using "\" means the following:
Your real line in the 1st case:
#asmmovlw 0x00movwf 0x00#endasm
The compiler will understand your #asm and #endasm words, but "movlw 0x00movwf 0x00" is not an assy instruction, indeed.
If you isolate the instructions (2nd case, but it is not an efficient way):
#asmmovlw 0x00#endasm the instruction between #asm and #endasm is "movlw 0x00" what is a real instr.

Conclusion: Use the "\" character only when you MUST enter a one-line directive otherwise.


:=Hello
:=
:=If I try the following...
:=
:=#any define...\
:=#asm\
:=movlw 0x00\ // any hex value
:=movwf 0x00\ // any register
:=#endasm\
:=
:=..I receive an error (Expecting an opcode mnemonic).
:=
:=If I change it to the following...
:=
:=#any define...\
:=#asm\
:=movlw 0x00\ // any hex value
:=#endasm\
:=#asm\
:=movwf 0x00\ // any register
:=#endasm\
:=...everything works ok.
:=
:=Any ideas why? Or did I miss something important?
:=
:=Thanks
:=mfg
:=Felix</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 1116
Felix Althaus



Joined: 09 Sep 2003
Posts: 67
Location: Winterthur, Switzerland

View user's profile Send private message

Re: in multi line macros
PostPosted: Thu Nov 15, 2001 7:28 am     Reply with quote

Hello
:=The #asm directive is NOT a macro.

I know, that #asm etc isn't a macro.
But I have to write a macro which returns a few assembly lines. And the compiler doesn't understand more than one mnemonic in one line. So I thought, I can do this with an \ after each mnemonic, but this doesn't work (as I said).

I there no other way without an #asm, #endasm around each instruction?

Thanks
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 1120
Tomi
Guest







Re: in multi line macros
PostPosted: Thu Nov 15, 2001 8:32 am     Reply with quote

Hi,
as I wrote the problem is the concatenating of the lines so the solution is very simple: add an extra SPACE character to each line before the "\" character:
#define myfunc() #asm movlw 0 \
movwf 0x10 \
clrwdt \
#endasm

The list:
0000 00324 .................... myfunc();
0061 3000 00325 MOVLW 00
0062 0090 00326 MOVWF 10
0063 0064 00327 CLRWDT

Hope this helps.
Tomi
___________________________
This message was ported from CCS's old forum
Original Post ID: 1123
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