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 ...
随机推荐
- Struts文件上传
首先要加入上传文件需要的jar文件 commons-fileupload-1.2.1.jar commomons-io-1.3.2.jar不同版本的strutsjar文件的版本也可能不同,一般在配置s ...
- OMCS开发手册(04) -- 二次开发流程
在掌握了前面几篇关于OMCS的详细介绍后,我们就可以正式基于OMCS进行二次开发了.下面我们就从服务端和客户端的角度分别介绍开发的步骤. 一.服务端开发 抛开具体的业务逻辑而言,就OMCS的服务端的开 ...
- C# 语言规范_版本5.0 (第2章 词法结构)
1. 词法结构 1.1 程序 C# 程序 (program) 由一个或多个源文件 (source file) 组成,源文件的正式名称是编译单元 (compilation unit)(第 9.1 节). ...
- table边框1px
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- poj1256(全排列stl)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;bool cmp ...
- iOS自定义转场动画的实现
iOS中熟悉的是导航栏中的push和pop这两种动画效果,在这里我们可以自己实现自己想要的一些转场动画 下面是我自己创建转场动画的过程 1.新建一个文件继承自NSObject ,遵循协议UIViewC ...
- eclipse设置java虚拟机内存大小
设置java虚拟机大小可以让eclipse启动运行更快...... 在eclipse中点击window--preferences--java--Installed JREs. 然后看右边的框,鼠标点击 ...
- 34.编写2个接口:InterfaceA和InterfaceB;在接口InterfaceA中有个方法void printCapitalLetter();在接口InterfaceB中有个方法void printLowercaseLetter();然 后写一个类Print实现接口InterfaceA和InterfaceB,要求printCapitalLetter()方法 实现输出大写英文字母表的功能,
//接口InterfaceA package jieKou; public interface IInterfaceA { void printCapitalLetter(); } //接口Inter ...
- CVE-2014-1767 漏洞分析(2015.1)
CVE-2014-1767 漏洞分析 1. 简介 该漏洞是由于Windows的afd.sys驱动在对系统内存的管理操作中,存在着悬垂指针的问题.在特定情况下攻击者可以通过该悬垂指针造成内存的doubl ...
- zendstudio 安装 手册
安装 http://jingyan.baidu.com/article/b907e627b14fbb46e6891c65.html 选择baidu官方32bit安装 补丁破解网址 http://dwt ...