How do you call an assembly function from C program?

不打扰是莪最后的温柔 提交于 2019-12-01 13:36:36

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:] [<instruction> [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.

There's a way to use asm in C language, depending on the compiler you use (the capacity to use asm in C is not part of the standard). Each compiler doesn't use the same syntax. With MPLAB C18 it's something like this:

void main()
{
     _asm
                movlw 0x57
                movwf PORTB
    _endasm
}

The example above is from this link, which will explain you how to use asm in C with MPLAB C18.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!