asmscript

Overview

asmscript (aka asms) is a JIT-compiled programming language made in 48h for the third langjam hosted at langjam/jam0003 on GitHub. The theme was Beautiful Assembly.

This is a low-level language, which attempts to make x86_64 assembly look more structured and easier to read. The scope of this language is very limited because of the time constraints, but it is capable of doing some basic computations.

The source for this project is hosted on GitHub.

Features

Examples

Print integers from 1 to 100.

// A procedure named "main", which is the entry point
proc main {
    rax = 1;

    loop (rax <= 100) {
        << rax;   // Print value in rax to stdout
        << "\n";  // Print newline to stdout
        rax += 1;
    }
}

Print prime numbers between 2 and 100.

// This procedure will print the rax register if it contains a prime
proc prime_test {
    rbx = 2; // Our divisor
    loop { // Loop without a condition is an infinite loop
        // We only need to test divisors in range [2, sqrt(rax)]
        // Loop until rbx * rbx <= rax
        r8 = rbx;
        r8 *= rbx;
        break if r8 > rax; // Is prime, break and print the value

        rdx = rax;
        rdx %= rbx;
        return if rdx == 0; // Not prime, return without printing

        rbx += 1;
    }

    << rax;
    << "\n";
}

proc main {
    rax = 2;
    loop (rax <= 100) {
        prime_test; // Call the "prime_test" procedure
        rax += 1;
    }
}