Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9086884
  • 博文数量: 1732
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19830
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1732)

文章存档

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: C/C++

2013-07-04 10:37:01

http://www.cnblogs.com/jack204/archive/2011/09/13/2175011.html

1 内嵌汇编

1)__asm__用于指示编译器在此插入汇编语句
2)__volatile__用于告诉编译器,严禁将此处的汇编语句与其它的语句重组合优化。 即:原原本本按原来的样子处理这这里的汇编。

 

 

The format of basic inline assembly is very much straight forward. Its basic form is asm("assembly code");
Example.



asm("movl %ecx %eax"); /* moves the contents of ecx to eax */
__asm__("movb %bh (%eax)"); /*moves the byte from bh to the memory pointed by eax */


 

You might have noticed that here I’ve used asm and __asm__. Both  are valid. We can use __asm__ if the keyword asm conflicts with something in our program. If we have more than one instructions, we write one per line in double quotes, and also suffix a ’\n’ and ’\t’ to the instruction. This is because gcc sends each instruction as a string to as(GAS) and by using the newline/tab we send correctly formatted lines to the assembler.

2 c文件和asm文件链接(使用gnu as汇编器)

先假设c文件中有函数c_func,调用asm文件的函数asm_func,那么c中的声明为:


void c_func(); void asm_func();

而在asm中要有相应的函数和声明为,现在假设c函数使用c calling conversion。那么name mangle的时候会在名字前加上下划线变为_c_func。
所以在汇编asm和c一起链接的时候,一定要确定好c中使用的那种方式的name mangle。对应的asm中的代码为:

加了下划线是因为c编译时候有name mangle的原因。
命令为:
gcc -o sth.exe file.c file.s.

 

阅读(3277) | 评论(0) | 转发(0) |
0

上一篇:iwconfig配置

下一篇:windows 自动登录

给主人留下些什么吧!~~