Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 30, 2024, 06:50:54 06:50


Login with username, password and session length


Pages: [1]
Print
Author Topic: MicroC, Macros, inline asm and parameters  (Read 4446 times)
0 Members and 2 Guests are viewing this topic.
Elysion
Newbie
*
Offline Offline

Posts: 14

Thank You
-Given: 27
-Receive: 1


« on: March 08, 2015, 12:42:18 12:42 »

Hi,

I have a function like below. How could I make it compile?

MacroTest.c below

Code:
#include "MacroTest.h"

void main() {
    char var1;
   
    var1 = 80;

    SaveBankSelectRegister(var1);
}

MacroTest.h below

Code:
#ifndef __Macro
#define __Macro

#define SaveBankSelectRegister(SaveVariable)          asm { movff  BSR, SaveVariable }

#endif

Quote
Undeclared identifier '_var1' in expression MacroTest.c

Normally, if I use this as a function, I put a "_" infront of the variable in asm like below. What about using it in macros?

Code:
void SaveBankSelectRegister(char saveVariable)
{
   asm { movff  BSR, _saveVariable } 
}
Logged
flo0319
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 7
-Receive: 17


« Reply #1 on: March 08, 2015, 01:51:11 13:51 »

Hi , you need to use the concatenate operator ##

   
Code:
#define SaveBankSelectRegister(SaveVariable)          asm { movff  BSR, _##SaveVariable }
Logged
zuisti
Senior Member
****
Offline Offline

Posts: 409

Thank You
-Given: 242
-Receive: 780


« Reply #2 on: March 08, 2015, 09:21:54 21:21 »

This form is working:

Code:
#define SaveBankSelectRegister(SaveVariable)   asm  movff  BSR, _##SaveVariable

char var1; // global, to save BSR

void main() {

    SaveBankSelectRegister(var1);
}
Logged
Elysion
Newbie
*
Offline Offline

Posts: 14

Thank You
-Given: 27
-Receive: 1


« Reply #3 on: March 25, 2015, 09:17:02 21:17 »

Hi,

I have the below code. How is the correct phrase? Thanks.


source:
Code:
#include "MacroTest.h"

char  x1;
char  x2;

void main() {

    x1 = 1;
    x2 = 1;

    TestMacro(x1);
}

header:
Code:
#define TestMacro(sample )    _asm { movf        _##sample+1,0,1         \
                                        xorwf         _x2+1,0,1     \
                                   }\


Posted on: March 25, 2015, 08:50:42 20:50 - Automerged

Ok. Smiley ";" done all the magic.

Thanks
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC