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的更多相关文章

  1. Beennan的内嵌汇编指导(译)Brennan's Guide to Inline Assembly

    注:写在前面,这是一篇翻译文章,本人的英文水平很有限,但内嵌汇编是学习操作系统不可少的知识,本人也常去查看这方面的内容,本文是在做mit的jos实验中的一篇关于内嵌汇编的介绍.关于常用的内嵌汇编(AT ...

  2. Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)【转】

    转自:http://www.linuxidc.com/Linux/2013-06/85221p3.htm 阅读Linux内核源码或对代码做性能优化时,经常会有在C语言中嵌入一段汇编代码的需求,这种嵌入 ...

  3. 《Brennan's Guide to Inline Assembly》学习笔记

    原文见Brennan's Guide to Inline Assembly. AT&T语法 vs Intel语法 DJGPP是基于GCC的,因此它使用AT&T/UNIT语法,这和Int ...

  4. 【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)

    http://blog.csdn.net/slvher/article/details/8864996 https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm. ...

  5. [转]iOS Assembly Tutorial: Understanding ARM

    iOS Assembly Tutorial: Understanding ARM Do you speak assembly? When you write Objective-C code, it ...

  6. error: invalid 'asm': invalid operand for code 'w'

    google 出结果 http://stackoverflow.com/questions/15623609/including-curl-into-the-android-aosp ........ ...

  7. Java字节码—ASM

    前言 ASM 是什么 官方介绍:ASM is an all purpose Java bytecode manipulation and analysis framework. It can be u ...

  8. MIT-6.828-JOS-lab1:C, Assembly, Tools, and Bootstrapping

    Lab1:Booting a PC 概述 本文主要介绍lab1,从内容上分为三部分,part1简单介绍了汇编语言,物理内存地址空间,BIOS.part2介绍了BIOS从磁盘0号扇区读取boot loa ...

  9. RFID 仿真/模拟/监控/拦截/检测/嗅探器

    Sound card based RFID sniffer/emulator (Too tired after recon.cx to do draw the schematics better th ...

随机推荐

  1. 1、第一个SpringMVC程序

    1.创建如下项目结构 2.在src下的com.springmvc下创建User.java package com.springmvc; public class User { private Stri ...

  2. Java实现二分查找算法

    Java程序员总该玩点基本的算法. 1.前提:二分查找的前提是需要查找的数组必须是已排序的,我们这里的实现默认为升序 2.原理:将数组分为三部分,依次是中值(所谓的中值就是数组中间位置的那个值)前,中 ...

  3. MaskEdit组件的EditText属性和Text属性

    MaskEdit组件主要是EditMask属性 是string属性. 掩码字符串EditMask属性分为3个部分,分别用分号隔开,形式是“XXXXX;X;X” 第一部分是掩码字符串的主要部分,它确定输 ...

  4. ubuntu安装docker

    uname -r #查看内核版本要大于3.10apt-get updateapt-get install linux-image-generic-lts-trusty wget -qO- https: ...

  5. LeetCode OJ 85. Maximal Rectangle

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...

  6. LightOJ 1337 F - The Crystal Maze (bfs)

    Description You are in a plane and you are about to be dropped with a parasuit in a crystal maze. As ...

  7. digitalocean纽约机房最先开通IPv6

    DigitalOcean是一家位于美国的云主机服务商,总部位于纽约,成立于2012年.DigitalOcean的服务器全部采用KVM架构,具体高性能处理能力,并且配备SSD固态硬盘,速度优异.每台设备 ...

  8. great C++ socket library

    NETLINK: http://netlinksockets.sourceforge.net/index.html

  9. CentOS 7 多网卡绑定

    根据官方文档Red_Hat_Enterprise_Linux-7-Networking_Guide-en-US用nmcli做起来还是相当容易的.下面把俺的步骤贴下. 1.查看目前网卡的名称和状态.#n ...

  10. mongoDB4--mongoDB的增删改查

    MongoDb基本操作之增删改查我们知道传统关系型数据库的最常用操作就是"增加/删除/修改/查询",也就是传说中的CRUD(create/remove/updte/delete). ...