| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2718 人关注过本帖
标题:DEV-C++内联汇编问题
只看楼主 加入收藏
zlmbh
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-7-20
收藏
 问题点数:0 回复次数:5 
DEV-C++内联汇编问题
#include <stdio.h>
#include <stdlib.h>

int a = 10;
int b = 20;
int result;
 
int main()
{
    asm
    (
        "pusha\n\t"
        "movl a,%eax\n\t"
        "movl b,%ebx\n\t"
        "imull %ebx,%eax\n\t"
        "movl %eax,result\n\t"
        "popa"
    );

    printf("%d\n",result);   
    return 0;
}

上面的代码是教科书里的,教程中说内联汇编要访问的变量必须是全局的,我认为程序没有问题,但编译运行时报错:

Compiler: Default compiler
Executing  gcc.exe...
gcc.exe "E:\xx\test\test.c" -o "E:\xx\test\test.exe"    -I"d:\Dev-Cpp\include"   -L"d:\Dev-Cpp\lib"
C:\DOCUME~1\xxx\LOCALS~1\Temp/ccUlaaaa.o(.text+0x38):test.c: undefined reference to `a'
C:\DOCUME~1\xxx\LOCALS~1\Temp/ccUlaaaa.o(.text+0x3e):test.c: undefined reference to `b'
C:\DOCUME~1\xxx\LOCALS~1\Temp/ccUlaaaa.o(.text+0x46):test.c: undefined reference to `result'collect2: ld returned 1 exit status

Execution terminated

请教大家,问题出在哪里??3x
搜索更多相关主题的帖子: 内联 汇编 
2008-07-20 23:59
fxstudenting
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-7-28
收藏
得分:0 
这个问题我能帮你解答,去这个两博客其中的一个,把问题写到留言版上,我马上给你解答。
http://dlstudenting.
http://fxstudenting.blog.
2008-07-29 09:33
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
恶心


http://hi.baidu.com/cnbinghu/blog/item/70b3a5fb29b1f6274f4aea91.html

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-07-29 09:46
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
內嵌匯編不是標準里面的 各種編譯器也不一樣
建議你int a = 10;前面加一個extern
asm(里面的a改成_a試試
具體能不能行我也不清楚 P.S.不是必須最好不要用內嵌匯編

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-07-29 11:47
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
楼主问的是DEV-CPP里的,就是gcc内联汇编的用法。通常在接触底层硬件时用。

lingluoz,给你推荐一个IDE,里头有TC风格控制台函数,见你用api封装过,这里有现成的。
----------------------------------------------------------------
这是LCC主页:
http://www.cs.virginia.edu/~lcc-win32/
下载页:
http://www.q-software-solutions.de/downloaders/get_name
点下边的“Get me to the downloads”进入下载页。


LCC的库在C标准库的基础上:支持模板实现了C++的常见数据结构的容器,高级数学函数,线性代数,统计学,网络,TC风格控制台操作,加密解密,GC垃圾回收,位操作,perl风格正则表达式,posix风格正则,内存数据压缩解压。
--------------------------------------------------------------------

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-07-29 12:02
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
恩。。試試

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-07-29 13:02
快速回复:DEV-C++内联汇编问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012365 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved