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
- Support for 15 general purpose registers (all except rsp), only in 64-bit form.
- Operations on 64-bit signed integers: addition, subtraction, multiplication, division, modulo, bitwise and, or, xor.
- Support for 64-bit signed integer literals, even when x86_64 instruction don't accept 64-bit immediate values directly.
- Branches resembling if/else statements from higher level languages.
- Loops resembling while loops from higher level languages.
- Control flow statements: continue, break and return.
- Bare-bones procedure support (leaves calling convention up to you).
- Indirect stack control through push and pop statements.
- Print formatted numbers and string constants to stdout.
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; } }