Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tenderlove/aarch64
Pure Ruby ARM64 Assembler
https://github.com/tenderlove/aarch64
arm64 assembly ruby ruby-assembler
Last synced: 6 days ago
JSON representation
Pure Ruby ARM64 Assembler
- Host: GitHub
- URL: https://github.com/tenderlove/aarch64
- Owner: tenderlove
- License: apache-2.0
- Created: 2022-03-16T23:43:16.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T11:24:46.000Z (8 months ago)
- Last Synced: 2025-01-08T18:08:49.645Z (14 days ago)
- Topics: arm64, assembly, ruby, ruby-assembler
- Language: Ruby
- Homepage:
- Size: 1.02 MB
- Stars: 67
- Watchers: 5
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# AArch64
This is a pure Ruby ARM64 assembler. Are you tired of writing Ruby in Ruby?
Now you can write ARM64 assembly in Ruby with this gem!## Example
This example uses the DSL methods. The DSL methods make accessing the
registers, shifts, and options a little more easy.```ruby
require "aarch64"
require "jit_buffer"# create a JIT buffer
jit_buffer = JITBuffer.new 4096asm = AArch64::Assembler.new
# Make some instructions
asm.pretty do
asm.movz x0, 0xCAFE
asm.movk x0, 0xF00D, lsl(16)
asm.ret
end# Write the instructions to a JIT buffer
jit_buffer.writeable!
asm.write_to jit_buffer
jit_buffer.executable!# Execute the JIT buffer
p jit_buffer.to_function([], -Fiddle::TYPE_INT).call.to_s(16) # => f00dcafe
```The following is the same example, but without the DSL. The main difference is
that you must access registers via the constant names.```ruby
require "aarch64"
require "jit_buffer"# create a JIT buffer
jit_buffer = JITBuffer.new 4096
asm = AArch64::Assembler.new# Make some instructions
asm.movz AArch64::Registers::X0, 0xCAFE
asm.movk AArch64::Registers::X0, 0xF00D, lsl: 16
asm.ret# Write the instructions to a JIT buffer
jit_buffer.writeable!
asm.write_to jit_buffer
jit_buffer.executable!# Execute the JIT buffer
p jit_buffer.to_function([], -Fiddle::TYPE_INT).call.to_s(16) # => f00dcafe
```You can include `AArch64::Registers` if you don't want to use the DSL, but
want easier access to the registers. For example:```ruby
include AArch64::Registersasm = AArch64::Assembler.new
asm.movz X0, 0xCAFE
asm.movk X0, 0xF00D, lsl: 16
asm.ret
```Here is another example of the same assembly, but using the built-in ARM64
assembly parser:```ruby
require "jit_buffer"
require "aarch64/parser"parser = AArch64::Parser.new
asm = parser.parse <<~eoasm
movz x0, 0xCAFE
movk x0, 0xF00D, lsl #16
ret
eoasm# create a JIT buffer
jit_buffer = JITBuffer.new 4096# Write the instructions to a JIT buffer
jit_buffer.writeable!
asm.write_to jit_buffer
jit_buffer.executable!# Execute the JIT buffer
p jit_buffer.to_function([], -Fiddle::TYPE_INT).call.to_s(16) # => f00dcafe
```## Hacking / Contributing
Hacking on this gem should be similar to most. Just do:
```
$ gel install
$ gel exec rake test
```