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

  免費注冊 查看新帖 |

Chinaunix

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

請教一個擴展匯編的問題 [復(fù)制鏈接]

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

論壇徽章:
2
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:17
2 [報告]
發(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 [報告]
發(fā)表于 2007-06-20 15:52 |只看該作者
這個我看了,能解釋一下嗎?不明白用與不用的區(qū)別
我把一些代碼翻譯了一下,有沒有&都是一樣的,一個字的區(qū)別都沒有

論壇徽章:
0
4 [報告]
發(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.
__________________

翻譯一下:

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

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

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

(把原來的錯誤理解刪除)

如果不加&符號, 舉例來說, 如果寄存器不夠用,GCC很可能為 輸出操作數(shù)"=b"和輸入操作數(shù)"a"使用同一個寄存器, 因為它假設(shè): 在產(chǎn)生輸出之前, 輸入操作數(shù)就已經(jīng)用完了,不需要了。

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



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

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

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

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

#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);
}


這個代碼編譯出錯,因為沒有通用寄存器可用
但是如果沒有&,則可以重用
        .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是輸入
      ####如果這個后面還有代碼要使用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 [報告]
發(fā)表于 2007-11-22 10:36 |只看該作者
我見過最好的兩篇gcc inline asm文檔
第一篇是很多人都看過的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 [報告]
發(fā)表于 2007-11-22 10:50 |只看該作者
第一篇看過,在你的博客中看到過,有時間看看
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP