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.

C for 8051 question - Passing arguments from C code to ASM

Status
Not open for further replies.

mcoster

Member level 2
Joined
Jan 26, 2004
Messages
51
Helped
7
Reputation
14
Reaction score
1
Trophy points
1,288
Activity points
633
Hi,

I am developing a program and i decided to build the user interface in C, since it is easier, and the main code in ASM, since it is time-critical.

Now i am facing a problem ! I don´t know how to pass a argument form the C code part to the ASM code part.

For example, i want to put a value in one of the registers or any part of the memory using C and then get this value using ASM.

Doing the ASM part is easy it is just a couple of MOV commands but how to store a value inside the RAM or a register using C is the part i can´t figure it out !
Can anyone help me ?

Code example

main()
{
code that store the value 0xC0 in R0
}

#pragma ASM

MOV P0,R0

#pragma ENDASM


Thanks !
 

This is compiler specific. Some compilers pass parameters on the stack, some do it in registers. You have the check the documentation of the compiler that you are using.

There is an alternate way to check this also. You can write the funciton in C as

extern void ASMfunction(unsigned char);

then call this from C

ASMfunction(parameter);

Then you can check the asm code generated by the C compiler to see how the parameter is passed
 

    mcoster

    Points: 2
    Helpful Answer Positive Rating
Re: C for 8051 question - Passing arguments from C code to A

Look at the example https://www.keil.com/support/man/docs/c51/c51_ap_at.htm

char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */

inside main function :

text[0] = 'a';

Later in your asm code part you can do this:

MOV DPTR, #E000h
MOVX A, @DPTR
;Acc now get the 'a' wrote in C

I've tried to follow the same layout procedure mentioned by you as example. Like you wrote:
" how to pass an argument from the C code part to ASM code part"
and
"How to store a value inside the RAM or a register using C"

For a much in depth explanation read the Cx51 user's guide:
https://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm
 

    mcoster

    Points: 2
    Helpful Answer Positive Rating
You cannot access the registers directly in C. You can however do that using pointers. Direct RAM access is also made using pointers. But accessing registers by pointers is dangerous.

Ke*il has a fairly good documentation of passing paramters. I think it goes like this. For a single byte, it is done through R7 and so on.
 

    mcoster

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top