![](/img/trans.png)
[英]compiling linux 0.0.1 => error: ‘asm’ operand has impossible constraints __asm__(“cld\n”
[英]Not compile in x86_32 ( error _ impossible contraint in __asm__ )
我在x86_64中編寫此代碼,並編譯並運行良好,
__asm__("nop"
: "=eax"(foo)
: //"eax"(foo),"ebx"(bar)
: "eax"
);
但是當我嘗試在其他機器(x86_32)上進行編譯時,gcc會觸發錯誤:S
inline1.c:6: error: impossible constraint in _asm_
我無法解決..:S
GCC版本::
未編譯 :
tur@aso:~$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' -- with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable- languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch -- enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
線程模型:posix gcc版本4.4.3(Ubuntu 4.4.3-4ubuntu5.1)
編譯
git@srvcode:/home/git/code/asm$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1- 9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
線程模型:posix gcc版本4.6.1(Ubuntu / Linaro 4.6.1-9ubuntu3)
謝謝大家!
阿圖爾
nop
是無操作數的指令。 如果內聯中沒有使用任何操作數,則gcc無法為使用的操作數分配任何寄存器,這可能是設置任何輸入/輸出寄存器失敗的原因。 但是,指令沒有修改寄存器,所以我很好奇為什么您認為需要保留eax
。
其次,在舊版本的gcc中,寄存器不能同時在輸入/輸出列表和Clobber列表上。 當然,自然會假定輸入/輸出列表上的寄存器是“密集的”。 為了向后兼容,最好調整該行為。
另外,您應該記住,內聯匯編中的寄存器操作數不是使用其實際名稱指定的(Clobber列表除外)。 而是使用描述寄存器的單個字母。 因此,對於eax
,我們有a
;對於ebx
,我們有b
,依此類推。 您可能還想閱讀GCC內聯匯編HOWTO ,它是有關該主題的信息的絕佳資源。
總結一下,類似的東西應該會更好:
__asm__("nop"
: /* no output */
: /* no input */
: "%eax" /* eax is clobbered */
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.