How to use Inline Assembly with MPLAB C18?

元气小坏坏 提交于 2019-12-11 05:47:34

问题


I am using MPLAB C18 which provides an internal assembler to enable calling assembly functions from a C project. I am following the rules on how to use Inline Assembly and I suspect something about 'Full text mnemonics must be used for table reads/writes' is causing a syntax error message upon building my project.

The internal assembler differs from the MPASM assembler as follows: 

No directive support

Comments must be C or C++ notation
Full text mnemonics must be used for table reads/writes. i.e.,
TBLRD
TBLRDPOSTDEC
TBLRDPOSTINC
TBLRDPREINC
TBLWT
TBLWTPOSTDEC
TBLWTPOSTINC
TBLWTPREINC
No defaults for instruction operands - all operands must be fully specified
Default radix is decimal
Literals are specified using C radix notation, not MPASM assembler notation. For example, a hex number should be specified as 0x1234, not H'1234'.
Label must include colon
Indexed addressing syntax (i.e., []) is not supported - must specify literal and access bit (e.g., specify as CLRF 2,0, not CLRF [2])

This is the code I am using which I got from the PIC18F87J11 datasheet about reading from flash memory.

MOVLW CODE_ADDR_UPPER ; Load TBLPTR with the base
MOVWF TBLPTRU ; address of the word
MOVLW CODE_ADDR_HIGH
MOVWF TBLPTRH
MOVLW CODE_ADDR_LOW
MOVWF TBLPTRL 
READ_WORD
TBLRD*+ ; read into TABLAT and increment
MOVF TABLAT, W ; get data
MOVWF WORD_EVEN
TBLRD*+ ; read into TABLAT and increment
MOVF TABLAT, W ; get data
MOVWF WORD_ODD

This is the modification I made in order to get the assembly code working. I suspect something about the TBLRD*+ is causing a syntax error.

 _asm

MOVLW CODE_ADDR_UPPER 
MOVWF TBLPTRU 
MOVLW CODE_ADDR_HIGH
MOVWF TBLPTRH
MOVLW CODE_ADDR_LOW
MOVWF TBLPTRL 
READ_WORD:
TBLRD*+ 
MOVF TABLAT, W 
MOVWF WORD_EVEN
TBLRD*+ 
MOVF TABLAT, W 
MOVWF WORD_ODD

_endasm 

I hope somebody can clarify what 'Full text mnemonics must be used for table reads/writes' means and what might be causing the build error.

Thanks!


回答1:


I will have to double check, but I believe that you have to replace TBLRD*+ with the mnemonic TBLRDPOSTINC. I'll post an edit later to confirm.



来源:https://stackoverflow.com/questions/17865676/how-to-use-inline-assembly-with-mplab-c18

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