cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1285|回复: 0

keil c6.20c 直接嵌入汇编的方法

[复制链接]
发表于 2004-11-6 03:25:21 | 显示全部楼层 |阅读模式
上此站以来,得到大家的很多的帮助,感谢大家!特此奉上"点心"一块供大家品尝。希望
能增加你营养。
//<asm.h>
#ifdef ASM
         unsigned long shiftR1(register unsigned long);
#else   
         extern unsigned long shiftR1(register unsigned long);
#endif
//end of asm.h

//<asm.c>
#define ASM
#include <asm.h>
#include <reg52.h>
#pragma OT(4,speed)
unsigned long    shiftR1(register unsigned long    x)
{
    #pragma asm
    clr c
    mov a,r4
    rrc a
    mov r4,a

    mov a,r5
    rrc a
    mov r5,a

    mov a,r6
    rrc a
    mov r6,a

    mov a,r7
    rrc a
    mov r7,a
   
    #pragma endasm
    return(x);
}
//end of asm.c
将此源文件加入要编译的工程文件,
将光标指向此文件,选择右键菜单“option for file 'asm.c'”,
将属性单“properties”中的“Generate Assembler SRC File”“Assemble SRC File”
两项设置成黑体的“√”将“Link Public Only”的“√”去掉,再编译即可。
用此方法可以在c源代码的任意位置用#pragma asm和#pragma endasm嵌入汇编语句。
但要注意的是在直接使用形参时要小心,在不同的优化级别下产生的汇编代码有所不同,
可以察看对应的.lst文件看一看,得到正确的优化级别后,#pragma OT(x,speed)锁定
优化级别(这里的值是0-9)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-5-4 15:17 , Processed in 0.351316 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表