RASMATAZ: a safer assembler …
Saturday, November 12th, 2011I like Assembly language. Assembly is clean and simple and fast, although verbose. I like Ruby’s interactive command line (IRB). Ruby’s interactive command line is quick to start and easy to use to test snippets of code. So what about having both of these, that is RASMATAZ, an Assembler written in Ruby that you can interact with via IRB or just execute from the command line. The biggest win is not having to re-start you machine when the instructions go off and give the operating system conniptions.
This is an example of the assembly you can execute with RASMATAZ:
mov rax, [rdx]
label :spin
push rax
pop rcx
dec rcx
jnz :spin
The assembly loosely follows the Intel syntax and you can see the full instructions and add your own in the file ‘machine.rb’.
You can interact with RASMATAZ using IRB by starting IRB and issuing a load to load your program, for example:
> load 'example.rasm', nil
For here you can interact with your program using one of the following commands:
- registers
dumps the current values of the registers, for example
>registers
=> {:rax=>0, :rbx=>0, :rcx=>0, :rdx=>0, :rsi=>0, :rdi=>0, :rbp=>0, :rip=>0, :rsp=>0} - stack
dumps the current value on the stack, for example
=> [] - memory
dumps the current values in memory, for example
=> [#<RASMATAZ::Instruction:0×00000002924af8 @pointer=0, @mnemonic=:label, @arg1=:start>, … - step
steps forward by executing a single instruction. For example
#<RASMATAZ::Instruction:0×00000001c97308 @pointer=0, @mnemonic=:label, @arg1=:start>
=> 1 - go
executes from current instruction until the program ends.
RASMATAZ is written entirely in Ruby with the assembly instructions being a DSL, the machine, stack, memory and registers are all Ruby objects. The DSL is defined in the file rasmataz/dsl.rb and the instructions and the virtual machine they execute against are defined in the file rasmataz/machine.rb.
RASMATAZ is an experiment of mine to see how far I could go with an assembler with out of the box Ruby. It is at the proof of concept stage but available to anyone to fork and continue if they wanted to. I’ll be coming back to RASMATAZ at a future point to develop of prototype for a new type of virtual machine that is not based around executing instructions like traditional virtual machines.
The source for RASMATAZ is here on github.
