Linux 0.11汇编的语法问题

来源:互联网 发布:云计算龙头股 编辑:程序博客网 时间:2024/04/27 22:19

#define _set_tssldt_desc(n,addr,type) /
__asm__ ("movw $104,%1/n/t" /
        "movw %%ax,%2/n/t" /
        "rorl $16,%%eax/n/t" /
        "movb %%al,%3/n/t" /
        "movb $" type ",%4/n/t" /   //这里用了$" type ",后面用了"0x89"," type "在这里为何要加上双引号?另外type的前面为何加了“$”?AT&T汇编立即数前面才加"$"的啊,为何?
        "movb $0x00,%5/n/t" /
        "movb %%ah,%6/n/t" /
        "rorl $16,%%eax" /
        ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), /
         "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) /
        )

#define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x89"//这里的"0x89"又为何要加上双引号呢?
#define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x82")

 

原因解释:

因为在$" type "处的本意是要取type的内容作为立即数操作

简单比较一下几种形式

1) "movb type ,%4/n/t" /
得到的结果只是 movb type ,...

2)"movb $type,%4/n/t" /
得到的结果是type的地址movb $type,...

3)"movb " type ",%4/n/t" /
得到的结果是 type的内容,此时type应该是具有内容的数据,比如"0x89","test",而不能是常量0x89
      movb 0x89, ...

4)"movb $" type ",%4/n/t" /
这种形式即原代码形式,其中" " 部分解析出type的“内容”,$ 表示是立即数,得到的结果是
    movb $0x89, ....