智能车制作

标题: codewarrior里怎么在C中插入汇编? [打印本页]

作者: whut_RY    时间: 2011-10-21 09:21
标题: codewarrior里怎么在C中插入汇编?
RT.起因在PIT模块中 中断里清除标志位不能使用
PITTF_PTFx = 1;
上面这条语句等同于汇编中的
BSET PITTF_PTFx, #0x01
PDF中关于清除标志位有如下解释
A flag is cleared by writing a one to the flag bit. Always use store or move instructions to write a one in
certain bit positions. Do not use the BSET instructions. Do not use any C-constructs that compile to BSET
instructions.
“BSET flag_register, #mask” must not be used for flag clearing because BSET is a readmodify-
write instruction which writes back the “bit-wise or” of the flag_register and the mask into the
flag_register. BSET would clear all flag bits that were set, independent from the mask.
For example, to clear flag bit 0 use: MOVB #$01,PITTF.
要清除标志位,必须使用 MOVB #mask, flag_register 这条汇编语句或者C-constructs that compile to MOVB instructions.
我在论坛上搜到关于类似的贴:
http://www.znczz.com/thread-56088-1-1.html
那么怎么样用C结构的语句来实现汇编中MOVB结构?
在KEIL 中利用编译控制命令#pragma asm(用来标识所插入的汇编语句的起始位置)
和 #pragma endasm (用来标识所插入的汇编语句的结束位置)中插入汇编
类似的,还有一个问题,codewarrior里,C语言中如何插入汇编?
小弟初来乍到,望各位解答!
作者: whut_RY    时间: 2011-10-21 15:39
没人知道?
作者: mick0866    时间: 2011-10-21 19:28
看看
作者: chenrunshe_007    时间: 2011-10-21 22:52
本帖最后由 chenrunshe_007 于 2011-10-21 22:55 编辑

回复 1# whut_RY
有两点:1.所有能用汇编的程序在CW里面都能用C实现,楼主仔细找找Datasheet,里面肯定有清除标志位的寄存器,可以直接写入赋值。
2.在C中嵌入汇编是在C语言程序中加入
_asm
{
    MOVB XX XX
    BSET XX
    ....
};
好像是这样吧,具体格式不太记得了,不过你去查Datasheet,有些章节的后面有关于本模块的例程,一般都是有两个版本的例程,分别为C和汇编,参考一下就知道了。
作者: chenrunshe_007    时间: 2011-10-21 22:53
回复 1# whut_RY
闲话一句,又是碰到万剑哥的学弟学妹啊,看来whut这个前缀很多人用啊。
作者: whut_RY    时间: 2011-10-21 23:11
回复 4# chenrunshe_007
谢谢!
1.相当给力!我好好找找!
2.这个写法是对的,我刚问了同学,他也是这么说的!
作者: whut_RY    时间: 2011-10-21 23:13
回复 5# chenrunshe_007
虽然未当面见过wj前辈,但是作为whut人,必须向前辈致敬!whut智能车队伍必须V5起来!哈哈!
作者: 汪洋大海    时间: 2011-10-21 23:55
4#正解
作者: chenrunshe_007    时间: 2011-10-24 22:02
回复 7# whut_RY
我们好多智能车论坛的人都在深圳,有机会来深圳去华为找你前辈。
作者: whut_RY    时间: 2011-10-24 22:31
回复  whut_RY
我们好多智能车论坛的人都在深圳,有机会来深圳去华为找你前辈。
chenrunshe_007 发表于 2011-10-24 22:02

谢谢!有机会一定!现在为智能车好好努力!
作者: 尐精灵    时间: 2011-10-25 07:38
学习了
作者: jiubiao    时间: 2011-11-19 21:19
1:宏指令方式:EnableInterrupts;//开中断。2、可嵌入多条指令:asm{lda_PTB;}。3、单条指令asm eor #0b00000100;asm nop;4、单条指令:_asm nop;5、单条指令:asm “nop”;6、单/多条指令:asm(“eor #4”);asm(“nop;nop”);asm(“nop\n nop”);7、可嵌入多条指令:#asm       nop        nop      #endasm
摘自匠人手记
作者: 157688    时间: 2012-2-11 19:39
沙发
作者: BOZHIFU    时间: 2012-8-19 15:47
学习了·····




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2