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 ...
随机推荐
- BZOJ2141: 排队
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2141 分块加树状数组. 离散化之后,每一个块建一个树状数组.交换x,y,与x左边的数和y右 ...
- gsl安装(Linux系统)
1. 在gnu的ftp站点http://ftp.gnu.org/gnu/gsl/ 上, 下载最新的gsl-2.x.tar.gz 2. 解压下载好的gsl-2.x.tar.gz 压缩包,$tar -zx ...
- 11.hibernate的连接查询
1.创建如下javaweb项目结构 2.在项目的src下创建hibernate.cfg.xml主配置文件 <?xml version="1.0" encoding=" ...
- [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列
题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...
- NOIP2012-普及组复赛-第一题-质因数分解
题目描述 Description 已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数. 输入输出格式 Input/output 输入格式:输入只有一行,包含一个正整数n.输出格式:输出只 ...
- 倒叙筛除list
for(int i=list.Count-1;i>=0;i--) { if(list[i]) { list.RemoveAt(i); } }
- Eclipse没有提示了,按Alt+/ 也无代码提示
1.菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 ...
- Linux查找文件中的字符串命令
grep -nr 'archermind' -r, --recursive Read all files under each directory, recursively, following sy ...
- HDU - 1045 Fire Net(搜索)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
- 《JS权威指南学习总结--4.9.3in和instanceof运算符》
内容要点: 一.in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数数值的属性名,那么表达式返回true. 例如: va ...