How do you call an assembly function from C program?

前端 未结 2 795
生来不讨喜
生来不讨喜 2021-01-15 22:19

I am very new to Microcontroller programming particularly PIC18F87J11, and I am using MPLAB C18 compiler. I was reading the datasheet for various topics such as saving to me

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-15 22:28

    Without access to the compiler I can't test this, but the MPLAB C18 C Compiler User's Guide and Release Notes which I found here states:

    2.8.2 Inline Assembly

    MPLAB C18 provides an internal assembler using a syntax similar to the MPASM assembler. The block of assembly code must begin with _asm and end with _endasm. The syntax within the block is:

    [label:] [ [arg1[, arg2[, arg3]]]]

    ...

    So, it would seem to me that one solution might be to embed something like this in your .C file

    void myAsmFunction()
    {
      _asm
      // The asm code you've been looking at
      _endasm
    }
    

    Then call myAsmFunction from wherever appropriate. If you're wanting to include parameters and return values then it gets a little trickier.

提交回复
热议问题