6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

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
4
0

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
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?