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 ...
随机推荐
- CF 602C The Two Routes(dij+邻接矩阵)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...
- hdu_5908_Abelian Period(暴力)
题目链接:hdu_5908_Abelian Period 题意: 给你n个数字,让你找出所有的k,使得把这n个数字分为k分,并且每份的数字种类和个数必须相同 题解: 枚举k,首先k必须是n的约数,然后 ...
- CreateProcess注意的几个地方
1.CreateProcess失败,GetLastError返回998,应该是最后两个参数没有初始化导致的. 2.要使外部程序隐藏窗口运行,需要将STARTUPINFO的dwFlags指定为START ...
- Openjudge-计算概论(A)-整数奇偶排序
描述: 输入10个整数,彼此以空格分隔重新排序以后输出(也按空格分隔),要求:1.先输出其中的奇数,并按从大到小排列:2.然后输出其中的偶数,并按从小到大排列.输入任意排序的10个整数(0-100), ...
- 10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- MYSQL:SQL中Group By的使用
SQL中Group By的使用 1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By ...
- C C++ 中结构体与类
先来说说C和C++中结构体的不同 a) C语言中的结构体不能为空,否则会报错 1>d:\myproject\visual studio 2013\projects\myc++\main.c(71 ...
- PHP socket模拟POST请求
<?php if (! function_exists ( 'socket_post' )) { function socket_post($url, $data, $referer = '') ...
- 9---PIP 管理工具的使用
Python 不仅有强大的内置模块,还提供强大的三方模块. 官方网站: https://pypi.python.org/pypi 要适用三方的模块需要使用pip管理工具. 1.在安装pip前,请确认w ...
- Oracle字符串操作[转:http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html]
ORACLE 字符串操作 1 字符串连接 SQL> select 'abc' || 'def' from dual; 'ABC'|------abcdef 2 小写SQL>select ...