View previous topic :: View next topic |
Author |
Message |
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
in multi line macros |
Posted: Wed Nov 14, 2001 3:52 pm |
|
|
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 |
Posted: Wed Nov 14, 2001 4:46 pm |
|
|
:=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
|
Re: in multi line macros |
Posted: Wed Nov 14, 2001 5:11 pm |
|
|
:=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 |
Posted: Wed Nov 14, 2001 9:21 pm |
|
|
:=:=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 |
Posted: Thu Nov 15, 2001 2:39 am |
|
|
<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
|
Re: in multi line macros |
Posted: Thu Nov 15, 2001 7:28 am |
|
|
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 |
Posted: Thu Nov 15, 2001 8:32 am |
|
|
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 |
|
|
|