qtdszws 发表于 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又是什么意思?

qtdszws 发表于 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 is reg 0.
   w --likewise, print the HImode name of the register.
   k --likewise, print the SImode name of the register.

ouyangjinlin 发表于 2010-05-08 18:56

你把整个函数发出来,函数有参数的

ouyangjinlin 发表于 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)操作数。表示在使用完操作数之前,内容会被修改

帅绝人寰 发表于 2010-05-11 16:58

%k2的k我知道,不过aCD这种写法还真是第一次看到 —— 谁知道啥意思?

莫非, 像ir一样?

EricFisher 发表于 2010-05-11 18:07

回复 1# qtdszws


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

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

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

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

帅绝人寰 发表于 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 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*/

bluesea666 发表于 2010-05-15 14:34

学习了.

notion001 发表于 2010-05-15 23:28

"aCD"是所谓的constraint(约束)

notion001 发表于 2010-05-15 23:29

%k2用来描述打印格式
页: [1] 2
查看完整版本: 两个内嵌汇编问题