Keil Logo

C51: MIXING C AND ASSEMBLY


Information in this article applies to:

  • C51 Version 6.02
  • µVision Version 2.06

QUESTION

Do you have any examples of how to mix C and assembly?

ANSWER

The following example program shows how to mix C and assembly in your 8051 programs.

This example starts with a MAIN C function which calls a routine in assembly which then calls a C function.

The MAIN C module appears as follows:

extern void a_func (void);

void main (void)
{
a_func ();
}

The function a_func is an assembly routine:

NAME    A_FUNC

?PR?a_func?A_FUNC    SEGMENT CODE
        EXTRN   CODE (c_func)
        PUBLIC  a_func

        RSEG    ?PR?a_func?A_FUNC
a_func:
        USING   0
        LCALL   c_func
        RET

        END

Note that this assembly routine calls c_func which is a C function:

void c_func (void)
{
}

The actual code for the assembly module was generated using the SRC pragma and the following C source file:

extern void c_func (void);

void a_func (void)
{
c_func ();
}

You may download C2ASM2C.ZIP from the Keil web site.

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Monday, February 5, 2007


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.