VOOZH about

URL: https://qiita.com/kubo39/items/793871edf4bdcb0dd259

⇱ Crystalでインラインアセンブラ #Crystal - Qiita


👁 Image
6

Go to list of users who liked

4

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@kubo39

Crystalでインラインアセンブラ

6
Last updated at Posted at 2015-07-20

0.7.4から(部分的に、というかんじのようですが)インラインアセンブラを使えるようになりました。

さっそく試してみます。
環境はx86_64です。

def syscall(n : UInt64) : UInt64
 dst :: UInt64
 asm("syscall" : "={rax}"(dst)
 : "rax"(n)
 : "rcx", "r11", "memory"
 : "volatile")
 dst
end
 
GETPID = 39_u64
p syscall(GETPID) == Process.pid ## => true

gcc拡張構文のsyntaxがそのまま使えるので、新しく文法を覚えなくてもよいのがいいですね。

6

Go to list of users who liked

4
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6

Go to list of users who liked

4