Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Passing values from embedded c code to asm code in dsPIC

Status
Not open for further replies.

embeddedpower1

Newbie level 3
Newbie level 3
Joined
May 24, 2019
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
45
Hai,

I am trying to write codes in dsPIC33FJ64GS610. In code, some function am written with assembly.

i don't know how to pass the values from asm code to embedded C and vice versa. Is there any inline function for that.

Can anyone suggest a solution for this? Please Help me.
 

it's not working.
am using C30 compiler and mplab XIDE.

my issue is follows

c code
-------------

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
int X=123,Y=0;
void main()
{
asmfuct(); //calling function which asm code is written
 
}
 
asmfuct()
{
asm("MOV #123 ,W1"); // inline assembly code
}



i need to pass the data from W1 to Y. and X to W1.
how can i inerface with c code and asm code.

Please give me some ideas for this
 
Last edited by a moderator:

i need to pass the data from W1 to Y. and X to W1.
how can i inerface with c code and asm code.

Please give me some ideas for this

My idea is that you take this C30 user's manual and make it your best friend in the world. Then you refer to Chapter 8. Mixing Assembly Language and C Modules.

EXAMPLE 8-2: CALLING AN ASSEMBLY FUNCTION IN C
Code:
/*
** file: call1.c
*/
extern int asmFunction(int, int);
int x;
void
main(void)
{ 
    x = asmFunction(0x100, 0x200);
}

The assembly-language function sums its two parameters and returns the result.

;
; file: call2.s
; 

 .global _asmFunction
_asmFunction:  
add w0,w1,w0  
return 
.end

And if you absolutely want to use inline asm

EXAMPLE 8-3: PASSING C VARIABLES
This example demonstrates how to use the swap instruction (which the compiler does not generally use) :asm ("swap %0" : "+r"(var));
 

In addition to the "revolutionary" idea of reading the C30 tools manual. C30 is GNU-C, if you need additional info not contained in the C30 manual, you may also consult the original GCC manual "Using the GNU Compiler Collection".
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top