Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xyproto/machinecode

:vulcan_salute: Rust module and utility for executing machine code
https://github.com/xyproto/machinecode

assembly jit machinecode programming-language rust

Last synced: 20 days ago
JSON representation

:vulcan_salute: Rust module and utility for executing machine code

Awesome Lists containing this project

README

        

# Machinecode

Execute machine code.

This repo includes both a Rust package and a utility called `jitrun`.

It was inspired by this post: [Hello, JIT World: The Joy of Simple JITs](http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-simple-jits.html).

For a similar project written in Go, check out [jit](https://github.com/xyproto/jit).

## Example use on x86_64

Return the number `42`:

cargo run -p jitrun -- examples/42.mc

Contents of `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)
```

Calculate the square root of `1024`:

cargo run -p jitrun -- examples/sqrt.mc

Contents of `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)

```

## General info

* Version: 0.1.0
* License: BSD-3