[C语言] 【菜鸟求助】在keil C51中如何引用外部.A51文件中的汇编宏?

[复制链接]
1861|3
 楼主| imba_sid 发表于 2015-2-5 10:46 | 显示全部楼层 |阅读模式
在keil环境下,C文件需要引用一个外部的汇编宏,请教21朋友们怎么样可以做到?

亦或,在C51文件中如何定义一个嵌入的汇编宏?

为方便我贴下码源:
portSAVE_CONTEXT        MACRO               
                /* Push ACC first, as when restoring the context it must be restored
                last (it is used to set the IE register).  */
                PUSH                ACC               
                /* Store the IE register then disable interrupts. */                                       
                PUSH                IE               
                PUSH                B
                PUSH                DPX
                PUSH                DPH
                PUSH                DPL
                PUSH                PSW
                PUSH                AR0
                PUSH                AR1
                PUSH                AR2
                PUSH                AR3
                PUSH                AR4
                PUSH                AR5
                PUSH                AR6
                PUSH                AR7       
        ENDM
 楼主| imba_sid 发表于 2015-2-5 10:49 | 显示全部楼层
求助,
 楼主| imba_sid 发表于 2015-2-5 11:06 | 显示全部楼层
在SDCC中是如下定义的:

/*
* Macro to push the current execution context onto the stack, before the stack
* is moved to XRAM.
*/
#define portSAVE_CONTEXT()                                                                                                                                                \
{                                                                                                                                                                                                \
        _asm                                                                                                                                                                                \
                /* Push ACC first, as when restoring the context it must be restored                                        \
                last (it is used to set the IE register). */                                                                                        \
                push        ACC                                                                                                                                                                \
                /* Store the IE register then disable interrupts. */                                                                        \
                push        IE                                                                                                                                                                \
                clr                _EA                                                                                                                                                                \
                push        DPL                                                                                                                                                                \
                push        DPH                                                                                                                                                                \
                push        b                                                                                                                                                                \
                push        ar2                                                                                                                                                                \
                push        ar3                                                                                                                                                                \
                push        ar4                                                                                                                                                                \
                push        ar5                                                                                                                                                                \
                push        ar6                                                                                                                                                                \
                push        ar7                                                                                                                                                                \
                push        ar0                                                                                                                                                                \
                push        ar1                                                                                                                                                                \
                push        PSW                                                                                                                                                                \
        _endasm;                                                                                                                                                                        \
                PSW = 0;                                                                                                                                                                \
        _asm                                                                                                                                                                                \
                push        _bp                                                                                                                                                                \
        _endasm;                                                                                                                                                                        \
}
/*-----------------------------------------------------------*/

在keil中我把_asm        替换为#pragma asm 会提示#出错。
ayb_ice 发表于 2015-2-5 13:31 | 显示全部楼层
C当然不可以引用外部的宏了

做成子程序,声明好后,就可以调用了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

5

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部