亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 7286 | 回復(fù): 9
打印 上一主題 下一主題

請(qǐng)教一個(gè)擴(kuò)展匯編的問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-06-20 14:32 |只看該作者 |倒序?yàn)g覽
我在內(nèi)核代碼看匯編的時(shí)候,不明白'=&r'和'=r'是什么區(qū)別,看了n多資料都一樣的,就幾句話,還是沒(méi)看懂

論壇徽章:
2
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:17
2 [報(bào)告]
發(fā)表于 2007-06-20 15:18 |只看該作者
Unless an output operand has the `&' constraint modifier, GCC may
allocate it in the same register as an unrelated input operand, on the
assumption the inputs are consumed before the outputs are produced.
This assumption may be false if the assembler code actually consists of
more than one instruction.  In such a case, use `&' for each output
operand that may not overlap an input.  *Note Modifiers::.


`&'
     Means (in a particular alternative) that this operand is an
     "earlyclobber" operand, which is modified before the instruction is
     finished using the input operands.  Therefore, this operand may
     not lie in a register that is used as an input operand or as part
     of any memory address.

     `&' applies only to the alternative in which it is written.  In
     constraints with multiple alternatives, sometimes one alternative
     requires `&' while others do not.  See, for example, the `movdf'
     insn of the 68000.

     An input operand can be tied to an earlyclobber operand if its only
     use as an input occurs before the early result is written.  Adding
     alternatives of this form often allows GCC to produce better code
     when only some of the inputs can be affected by the earlyclobber.
     See, for example, the `mulsi3' insn of the ARM.

     `&' does not obviate the need to write `='.

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2007-06-20 15:52 |只看該作者
這個(gè)我看了,能解釋一下嗎?不明白用與不用的區(qū)別
我把一些代碼翻譯了一下,有沒(méi)有&都是一樣的,一個(gè)字的區(qū)別都沒(méi)有

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2007-06-20 16:03 |只看該作者
Unless an output operand has the `&' constraint modifier, GCC may
allocate it in the same register as an unrelated input operand, on the
assumption the inputs are consumed before the outputs are produced.
This assumption may be false if the assembler code actually consists of
more than one instruction.  In such a case, use `&' for each output
operand that may not overlap an input.
__________________

翻譯一下:

&只是用來(lái)約束輸出部的。  如果不指定&約束符, 則GCC有可能為一個(gè)輸入操作數(shù)和該輸出操作數(shù)使用同一個(gè)寄存器, 這是基于以下的假設(shè): 在產(chǎn)生輸出之前(把輸出寫入到寄存器), 作為輸入的寄存器內(nèi)容已經(jīng)不再需要了。   有時(shí)侯嵌入?yún)R編有很多條指令,這種假設(shè)可能是不對(duì)的, 有可能過(guò)早產(chǎn)生了輸出, 從而覆蓋了輸入。  加上&約束,就會(huì)告訴gcc使用另一個(gè)寄存器, 不要和輸入寄存器使用同一個(gè)。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2007-06-20 17:43 |只看該作者
有一丁點(diǎn)頭緒,如果我理解對(duì)了,那么就是說(shuō)'&'有時(shí)候是必須的,因?yàn)榉駝t輸入和輸出的順序在代碼中要保持先后。
如果寄存器不夠用,那么使用了'&'就表示在使用這個(gè)寄存器之前需要保存到某個(gè)內(nèi)存中.

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2007-06-20 18:01 |只看該作者
>> 如果寄存器不夠用,那么使用了'&'就表示在使用這個(gè)寄存器之前需要保存到某個(gè)內(nèi)存中.

(把原來(lái)的錯(cuò)誤理解刪除)

如果不加&符號(hào), 舉例來(lái)說(shuō), 如果寄存器不夠用,GCC很可能為 輸出操作數(shù)"=b"和輸入操作數(shù)"a"使用同一個(gè)寄存器, 因?yàn)樗僭O(shè): 在產(chǎn)生輸出之前, 輸入操作數(shù)就已經(jīng)用完了,不需要了。

輸出約束改成"=&b"能改變這一默認(rèn)的優(yōu)化。 "=&b"表示,這是一個(gè)"earlyclobber",可能會(huì)過(guò)早的損壞其他操作數(shù),所以你為我單獨(dú)分配個(gè)寄存器吧。    info手冊(cè)說(shuō), 加上&只可能讓gcc產(chǎn)生更優(yōu)代碼,沒(méi)有副作用。



這個(gè)問(wèn)題比較難在代碼中試驗(yàn),不過(guò)理論應(yīng)該就是這樣的。

[ 本帖最后由 albcamus 于 2007-6-21 09:38 編輯 ]

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2007-06-22 11:05 |只看該作者
樓主弄明白這個(gè)問(wèn)題沒(méi)有?

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2007-11-21 22:50 |只看該作者
今天翻精華,看見(jiàn)這個(gè)帖子,后來(lái)忘記這個(gè)帖子了
說(shuō)實(shí)話,其實(shí)我還是沒(méi)有完全理解,但是估計(jì)就是我現(xiàn)在理解的這個(gè)意思了

#include <stdio.h>
int main()
{
        unsigned short cs = 0;
        volatile unsigned short a,b,c,d,e,f;
        asm ("movw %%cs,%0\n\t"
                        :"=&r"(cs):"r"(a),"r"(b),"r"(c),"r"(d),"r"(e),"r"(f));
        printf("%x\n",cs);
}


這個(gè)代碼編譯出錯(cuò),因?yàn)闆](méi)有通用寄存器可用
但是如果沒(méi)有&,則可以重用
        .file        "cs.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string        "%x\n"
        .text
        .p2align 4,,15
.globl main
        .type        main, @function
main:
        leal        4(%esp), %ecx
        andl        $-16, %esp
        pushl        -4(%ecx)
        pushl        %ebp
        movl        %esp, %ebp
        subl        $40, %esp
        movl        %ecx, -16(%ebp)
        movzwl        -18(%ebp), %edx/////
        movl        %ebx, -12(%ebp)
        movl        %esi, -8(%ebp)
        movl        %edi, -4(%ebp)
        movzwl        -20(%ebp), %edi
        movzwl        -22(%ebp), %esi
        movzwl        -24(%ebp), %ebx
        movzwl        -26(%ebp), %ecx
        movzwl        -28(%ebp), %eax
#APP
        movw %cs,%dx//dx是輸入
      ####如果這個(gè)后面還有代碼要使用a的值(dx),那么將不是a原始的值
       
#NO_APP
        movzwl        %dx, %edx
        movl        %edx, 4(%esp)
        movl        $.LC0, (%esp)
        call        printf
        movl        -16(%ebp), %ecx
        movl        -12(%ebp), %ebx
        movl        -8(%ebp), %esi
        movl        -4(%ebp), %edi
        movl        %ebp, %esp
        popl        %ebp
        leal        -4(%ecx), %esp
        ret
        .size        main, .-main
        .ident        "GCC: (GNU) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)"
        .section        .note.GNU-stack,"",@progbits

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2007-11-22 10:36 |只看該作者
我見(jiàn)過(guò)最好的兩篇gcc inline asm文檔
第一篇是很多人都看過(guò)的GCC inline Assembly HOWTO:
http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

第二篇寫的更好,是1998年LKML上的郵件:
http://groups.google.com/group/m ... ad/ca8860dd41ddd42b

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2007-11-22 10:50 |只看該作者
第一篇看過(guò),在你的博客中看到過(guò),有時(shí)間看看
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP