Ctai Save

compile time assembly interpreter

Project README

compile-time (simplified) x86 assembly interpreter

Hello World example:

#include "string.hpp"
#include "execute.hpp"

#include <iostream>

using code = decltype(
    "push ebx "
    "pop eax "
constexpr auto ret_val = cai::execute_code<code>;

int main()
    std::cout << std::hex << ret_val;
    return 0;

cai::execute_code will parse, tokenize, execute code and return value from eax register. Startup ebx value is 0xbada55. Above program will push ebx to stack and pop from stack to eax. So eax will eventually contain 0xbada55.

Supported features

  1. Multithreading (including priorities)
  2. Dynamic memory
  3. input/output
  4. Couple of syscalls and stdlib functions
  5. Asm instructions

Of course awesomeness comes by default.


  1. Multithread fibonacci without synchronization


alt text

  1. Multithread fibonacci with synchronization

Execution flow:

create two slave threads
join these threads
exit thread

lock input mutex
read element to calculate from stdin
unlock input mutex
calculate fibonacci for this element
lock output mutex
write result to stdout
unlock output mutex
exit thread


alt text

  1. Unrealized dream

Didn't managed to compile this beast. My machine doesn't have enough amount of RAM, but here's the flow:

read N from input - number of elements to calculate
create structure that will fit
	-N-element array of uint8_t for elements
	-N-element array of uint32_t for results
	-(N + 5)-element array of uint16_t for tasks. + 5 because five tasks to end slave thread
	-5-element array of uint32_t for slaves ids
create tasks
	-N tasks to calculate fibonacci element
	-five tasks to end slave thread
create five slave threads. Pass pointer to the structure in `args` argument
join slaves
write results to stdout
exit thread

while true
	lock tasks array mutex
	get next task
	unlock tasks array mutex
	if next task is fibonacci
		calculate fibonacci
		lock results array mutex
		write result to array
		unlock results array mutex
	else if task is exit
		exit thread


In doc folder you can find syscalls and stdlib funcitons documentations. For now there is no documentation with supported asm instructions.

Open Source Agenda is not affiliated with "Ctai" Project. README Source: stryku/ctai
Open Issues
Last Commit
6 years ago

Open Source Agenda Badge

Open Source Agenda Rating