Chinaunix首页 | 论坛 | 博客
  • 博客访问: 244262
  • 博文数量: 32
  • 博客积分: 557
  • 博客等级: 中士
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-20 23:05
文章分类

全部博文(32)

文章存档

2015年(4)

2014年(2)

2012年(4)

2011年(22)

分类: C/C++

2011-06-28 20:20:39

Referrence:
1. GCC DOC: C Extensions::Extended Asm::
2. HOWTO: 

Base Inline: asm("assembly code");
Extended Asm:
asm ( assembler template 
 : output operands /* optional */ 
 : input operands /* optional */ 
 : list of clobbered registers /* optional */ 
 );

Operands = "ConstraintModifiers-Constraint"(Operand-Expr), Another, ...

Clobbered register: 
registers that may be modified in this inline asm instructions, or "memory" indicates that our instruction modifies memory in a unpredictable fashion, and will cause GCC to not keep memory values cached in registers across the assembler instruction. 

Constraint Modifiers: 
= + &
Constraint: 
m r g 0-9 and so on. Constrains tells where the operands come from, and where to put the operands.

__asm__ equals to asm key word.
__volatile__ equals to volatile key word. 
When it decorates variables, it means that the var can be modified by some external program routine.And when it decorates routines just like here, following the asm key word, it tells gcc to not do any optimization on these instuctions. I think it's the difference with "memory" clobber string.



阅读(1988) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~