謎's キッチン

謎のひとりごと。Amazon欲しい物リストはこちら: https://www.amazon.co.jp/hz/wishlist/ls/CCPOV7C6JTD2

gccのインラインアセンブラが使いにくい

asm ("movb %%bh, %%al\n" : "=a"  (rv) : "b"  (x));

これのレジスタ依存をやめたい(=qとqにしたい)訳だけどどうすればいいやら。
正解は以下らしい。どのドキュメントに書いてあったんだろうか。

asm ("movb %h1, %b0\n" : "=q"  (rv) : "q"  (x));

あとインラインアセンブラ周りの最適化が見た感じおかしげ。
"mov %al,%al"とか平然と吐いてくる。
あとreturnの後にあるラベルでリンカエラーこれは勘違い勘違いじゃないっぽい。よく分からん。
何かなぁ。

ここにまとまっていた。
http://www.osdever.net/tutorials/gccasmtut.php?the_id=68
>And then there are the x86-specific ones. These are, unfortunately, only listed in the i386.h header file in the GCC source (config/i386/i386.h), so you have to dig a bit for them.
おいおい…。
ところで、レジスタ退避(Clobbers。:::ここ)に"q"とか"y"とか使えないのかなぁ。
古い http://gcc.gnu.org/ml/gcc/1999-10n/msg00488.html 見るには、"memory"と"cc"だけ特別扱いだけど、他には無いらしい。以下とのことでdummyなアウトプット使ってくれだと。おいおい。


* Temporary registers

People also sometimes erroneously use clobbers for temporary registers.
The right way is to make up a dummy output, and use "=r" or "=&r"
depending on the permitted overlap with the inputs. GCC allocates a
register for the dummy value. The difference is that GCC can pick a
convenient register, so it has more flexibility.