免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4339 | 回复: 12
打印 上一主题 下一主题

两个内嵌汇编问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-04-29 14:39 |只看该作者 |倒序浏览
({                                                                             
    unsigned int resultvar;                                                     
    asm volatile (                                                             
    "bpushl .L__X'%k2, %k2\n\t"                                                     
    "bmovl .L__X'%k2, %k2\n\t"   
    "movl %1, %%eax\n\t"                                                     
    "int $0x80\n\t"                                                             
    "bpopl .L__X'%k2, %k2\n\t"
    : "=a" (resultvar)                                                             
    : "i" (11) , "aCD" (arg1), "c" (arg2), "d" (arg3) : "memory", "cc");                     
    if (resultvar >= 0xfffff001)                                             
      {                                                                             
        __set_errno (-resultvar);                                             
        resultvar = 0xffffffff;                                                     
      }                                                                             
    (int) resultvar; })

"aCD" 是什么意思?
%k2又是什么意思?

论坛徽章:
0
2 [报告]
发表于 2010-04-29 16:43 |只看该作者
“aCD" C好像不是有效的约束条件?

%k2

  b -- print the QImode name of the register for the indicated operand.
        %b0 would print %al if operands[0] is reg 0.
   w --  likewise, print the HImode name of the register.
   k --  likewise, print the SImode name of the register.

论坛徽章:
0
3 [报告]
发表于 2010-05-08 18:56 |只看该作者
你把整个函数发出来,函数有参数的

论坛徽章:
0
4 [报告]
发表于 2010-05-08 19:28 |只看该作者
代码
说明
代码
说明

a
使用寄存器eax
m
使用内存地址

b
使用寄存器ebx
o
使用内存地址并可以加偏移值

c
使用寄存器ecx
I
使用常数0-31

d
使用寄存器edx
J
使用常数0-63

S
使用esi
K
使用常数0-255

D
使用edi
L
使用常数0-65535

q
使用动态分配字节可寻址寄存器(eax、ebx、ecx或edx)
M
使用常数0-3

r
使用任意动态分配的寄存器
N
使用1字节常数(0-255)

g
使用通用有效的地址即可(eax、ebx、ecx、edx或内存变量)
O
使用常数0-31

A
使用eax与edx联合(64位)
=
输出操作数。输出值将替换前值

+
表示操作数可读可写
&
早期会变的(earlyclobber)操作数。表示在使用完操作数之前,内容会被修改

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:17
5 [报告]
发表于 2010-05-11 16:58 |只看该作者
%k2的k我知道,不过aCD这种写法还真是第一次看到 —— 谁知道啥意思?

莫非, 像ir一样?

论坛徽章:
2
摩羯座
日期:2013-10-10 14:29:04天蝎座
日期:2014-01-03 09:14:49
6 [报告]
发表于 2010-05-11 18:07 |只看该作者
回复 1# qtdszws


> "aCD" 是什么意思?
> %k2又是什么意思?

先说明一下 "aCD"是所谓的constraint(约束)
%k2是用在所谓的output template(输出模板)中,用来描述打印格式,类似于printf中的%s等。

最简单的约束种类是一个由字母组成的字符串,每个字母描述一种所允许的操作数。

除此之外,还会有机器特定的约束。参见:
http://hi.baidu.com/hellogcc/blo ... fae6156d22ebd0.html

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:17
7 [报告]
发表于 2010-05-12 11:06 |只看该作者
10822 /* Meaning of CODE:
10823    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
10824    C -- print opcode suffix for set/cmov insn.
10825    c -- like C, but print reversed condition
10826    E,e -- likewise, but for compare-and-branch fused insn.
10827    F,f -- likewise, but for floating-point.
10828    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
10829         otherwise nothing
10830    R -- print the prefix for register names.
10831    z -- print the opcode suffix for the size of the current operand.
10832    * -- print a star (in certain assembler syntax)
10833    A -- print an absolute memory reference.
10834    w -- print the operand as if it's a "word" (HImode) even if it isn't.
10835    s -- print a shift double count, followed by the assemblers argument
10836         delimiter.
10837    b -- print the QImode name of the register for the indicated operand.
10838         %b0 would print %al if operands[0] is reg 0.
10839    w --  likewise, print the HImode name of the register.
10840    k --  likewise, print the SImode name of the register.
10841    q --  likewise, print the DImode name of the register.
10842    x --  likewise, print the V4SFmode name of the register.
10843    t --  likewise, print the V8SFmode name of the register.
10844    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
10845    y -- print "st(0)" instead of "st" as a register.
10846    d -- print duplicated register operand for AVX instruction.
10847    D -- print condition for SSE cmp instruction.
10848    P -- if PIC, print an @PLT suffix.
10849    X -- don't print any sort of PIC '@' suffix for a symbol.
10850    & -- print some in-use local-dynamic symbol name.
10851    H -- print a memory address offset by 8; used for sse high-parts
10852    Y -- print condition for SSE5 com* instruction.
10853    + -- print a branch hint as 'cs' or 'ds' prefix
10854    ; -- print a semicolon (after prefixes due to bug in older gas).
10855  */

论坛徽章:
0
8 [报告]
发表于 2010-05-15 14:34 |只看该作者
学习了.

论坛徽章:
0
9 [报告]
发表于 2010-05-15 23:28 |只看该作者
"aCD"是所谓的constraint(约束)

论坛徽章:
0
10 [报告]
发表于 2010-05-15 23:29 |只看该作者
%k2用来描述打印格式
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP