2 个稳定版本
1.0.1 | 2023 年 8 月 8 日 |
---|
#169 in FFI
5KB
Machinecode
以十六进制形式执行机器码。
此仓库包含一个Rust包和一个名为 jitrun
的实用程序。
它受到以下帖子的启发: Hello, JIT World: The Joy of Simple JITs.
这是将 jit 从 Go 迁移到 Rust 的一个例子。
在 x86_64 上的示例用法
返回数字 42
cargo run -p jitrun -- examples/42.mc
42.mc
的内容
// This program moves 42 into eax and returns
b8 2a 00 00 00 // mov 0x2a000000 into the eax register. b8 is the "mov eax" part. 2a is 42.
c3 // return to the caller (the return value is held in eax)
计算 1024
的平方根
cargo run -p jitrun -- examples/sqrt.mc
sqrt.mc
的内容
// This program takes the square root of 1024 and returns the answer (in eax), which is 32
b8 00 04 00 00 // mov 1024 (0x0400) into eax (0x00 comes first and then 0x04, because it is little-endian)
f3 0f 2a c0 // mov eax into the xmm0 register
f3 0f 51 c0 // take the square root of the xmm0 register and place it into xmm0
f3 0f 2c c0 // move xmm0 back into eax
c3 // return to the caller (the return value is held in eax)
一般信息
- 版本:0.1.0
- 许可证:BSD-3
依赖项
~43KB