asm: Writing Inline Assembly
A usual IA includes these parts:
asm [volatile] ( AssemblerTemplate
: OutputOperands
[ : InputOperands
[ : Clobbers ] ]);
- the first line includes asm [volatile], it means the contents in the following parenthesis is IA.
- the AssblerTemplate is some assembler snippet, separated by ';', surrounded by "". for example, "mov %1 %%eax; mov %%eax %0" means to mov %1's content into %0. [first into %%eax, then into %0], note that the %N's N is the order of the CVars displays in the OutputOprands, and if N is larger than the total counts of the OOs, the exceeding is taken from vars above the assembly part, this part will be explained in the example.
- the OutputOprands is consist of 3 parts, the alias name, the constraints and the variable, this can be duplicated and separated by ','. like [asmVarName1] "=m"(CVar1),[asmVarName2] "+r"(CVar2)
- the InputOperands is almost the same as the OOs, but note that the constraints part should not begin with "+" "=" or other modifiers.
- the Clobber part, declare the parts of register name to be used, or if using memory, declare memory usage.
example:
#include <stdio.h>
int main()
{
//changes a and b's value
int a = , b = ;
asm(//note this program should be compile with gcc
"xchg %1,%%eax;xchg %%eax,%0"
:"=r"(b),"=m"(a)
:"r"(a)
:"%eax" //note register declare with one '%'
);
return ;
}
note the register %eax is not initialized. a's value should be unknown. b's value should be 10.
the question is, in assembler, mov a,b means pass b's value into a, however, here is the opposite, to pass a's value into b..
asm: Writing Inline Assembly的更多相关文章
- Beennan的内嵌汇编指导(译)Brennan's Guide to Inline Assembly
注:写在前面,这是一篇翻译文章,本人的英文水平很有限,但内嵌汇编是学习操作系统不可少的知识,本人也常去查看这方面的内容,本文是在做mit的jos实验中的一篇关于内嵌汇编的介绍.关于常用的内嵌汇编(AT ...
- Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)【转】
转自:http://www.linuxidc.com/Linux/2013-06/85221p3.htm 阅读Linux内核源码或对代码做性能优化时,经常会有在C语言中嵌入一段汇编代码的需求,这种嵌入 ...
- 《Brennan's Guide to Inline Assembly》学习笔记
原文见Brennan's Guide to Inline Assembly. AT&T语法 vs Intel语法 DJGPP是基于GCC的,因此它使用AT&T/UNIT语法,这和Int ...
- 【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)
http://blog.csdn.net/slvher/article/details/8864996 https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm. ...
- [转]iOS Assembly Tutorial: Understanding ARM
iOS Assembly Tutorial: Understanding ARM Do you speak assembly? When you write Objective-C code, it ...
- error: invalid 'asm': invalid operand for code 'w'
google 出结果 http://stackoverflow.com/questions/15623609/including-curl-into-the-android-aosp ........ ...
- Java字节码—ASM
前言 ASM 是什么 官方介绍:ASM is an all purpose Java bytecode manipulation and analysis framework. It can be u ...
- MIT-6.828-JOS-lab1:C, Assembly, Tools, and Bootstrapping
Lab1:Booting a PC 概述 本文主要介绍lab1,从内容上分为三部分,part1简单介绍了汇编语言,物理内存地址空间,BIOS.part2介绍了BIOS从磁盘0号扇区读取boot loa ...
- RFID 仿真/模拟/监控/拦截/检测/嗅探器
Sound card based RFID sniffer/emulator (Too tired after recon.cx to do draw the schematics better th ...
随机推荐
- (转) QImage总结
嗯,这个QImage的问题研究好久了,有段时间没用,忘了,已经被两次问到了,突然有点解释不清楚,我汗颜,觉得有必要重新总结下了,不然无颜对自己了. 图像的数据是以字节为单位保存的,每一行的字节数必须是 ...
- Java中需要总结的几个问题
慢慢总结,不然每次百度挺心烦的. 1. java文件的读写 2. String和StringBuffer的区别
- java.util.Iterator
public interface Iterator<E>: 对 collection 进行迭代的迭代器. 方法摘要: boolean hasNext() 如果仍有元素可以迭代,则返回 tr ...
- vmware虚拟机如何安装ubuntu14.10系统
vmware虚拟机安装ubuntu14.10系统安装步骤如下:
- git: reset
git reset --hard:把commit撤销,意思是不仅此次commit提交的文件从本地版本库的状态重置,而且把此次commit的文件也从本地目录中删除 所以如果你执行之后发现,git sta ...
- ORACLE小工具:存储过程清空所有表或使所有触发器失效
清空所有表: CREATE OR REPLACE PROCEDURE CLEAN_TABLES as v_tablename varchar2(256); cursor cur_tablename i ...
- ubuntu server 时区设置问题解决
1.当执行此命令的时候 ntpdate us.pool.ntp.org 出现一下错误提示 name server cannot be used: Temporary failure in name r ...
- 还原openstack配置文件的方法
cp -a /etc/neutron/neutron.conf /etc/neutron/neutron.conf.bakcp -a /etc/neutron/plugins/ml2/ml2_conf ...
- java发布项目后注意小点,以及对于金额在java中的处理
项目在发布之后,有时会进行一些小的地方的修改,特别是对于一些常量的修改,如定义的一些特殊账户,第三方的key值,当修改的时候,我之前就偷懒过,因为项目在服务器上面,访问速度也受到限制,替换整个项目很麻 ...
- hdu_2110_Crisis of HDU(母函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2110 题意:给你N个价值和数目,求方案数,很裸的母函数. #include<cstdio> ...