Archive for the ‘assembler’ Category

RASMATAZ: a safer assembler …

Saturday, November 12th, 2011

 pipes

I 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.

Assembler still alive and well ….

Sunday, December 9th, 2007

gretel

Today I received an email from a person interested in the Win32 IO Completion Ports example I did in assembler almost a year ago. My response to him follows at the bottom of this post. The project web site is no longer reachable so when I can find the archive of the latest code I have Ill post it here and to the MASM forum.

Assembler is a great language and while it is very granular the simplicity is something I like a lot. I’m still keen on assembler but I don’t find as much time as I would like to do it. Here is an example of Assembler using the Microsoft Macro Assembler, so you can see it is now similar to using a higher level language:

align 4
main_cleanup_io_workers proc svr:PFASTSVR, err:PDWORD

mov edx, svr
invoke PostQueuedCompletionStatus,
       [edx].FASTSVR.io_completion_port, 0, OPERATION_ENDED, NULL

mov edx, svr
invoke CloseHandle, [edx].FASTSVR.io_workers

ret
main_cleanup_io_workers endp

Why use assembler? because it is fun and there is a sense of awe in being as close to the metal as possible. The performance is also rather astonishing. In this day and age of trying to be more ‘green’ and carbon neutral there is also a satisfaction in knowing you can write programs that do more with less CPU and therefore less hardware drawing power and requiring cooling.

*The picture above is of one of my dogs, gretel. She is a pug and she makes me smile every day. I use this image as my avatar in the MASM forum.

E^Cube,

Thank you for your message and for your interest in FASTserver.

As six_l points out that particular code snippet is an example / tutorial on what is involved in using IOCP with Win32. It only accepts one connection at present, because the focus was on the IOCP API and not threading.

I did start working on a ‘framework’ that incorporated the IOCP stuff, so others could just write a DLL and not worry about all the other stuff. However, this didn’t go far, as I got busy on a lot of other things.

I’d be *very* interested in doing a project with you and others, to make a finished server with IOCP.
My only requirement would be that we don’t just focus on Win32 but Linux as well. This isn’t as hard as you might think so don’t let the multi-platform requirement put you off.

If your interested in doing this and with me leading the project then get in touch with me here or in my blog. I’ll also post about some great books to read on the subject in my blog shortly.

Keep well,

Assembly Language Programming

Sunday, February 4th, 2007

I have done a bit of assembly language programming in my win32 and linux server project. Mostly using the Gnu Assembler (GAS) and Gnu tool chain. When I started I found the best source of help and information in the MASM forums. There is a great bunch of people there.