1
4
Fork
You've already forked casm
0
C-like Assembler
  • Roff 100%
2026年05月28日 11:18:30 +09:00
doc doc: add name precedence rule 2026年05月28日 11:18:30 +09:00
casm.1 doc: merge from dev 2026年05月24日 19:49:41 +09:00
CONTRIBUTING.md doc: add project contribution rule document 2026年03月29日 15:09:04 +09:00
LICENSE feat: add non-source elements 2025年05月14日 19:30:23 +09:00
README.md doc: change example code from x86_64 to AArch64 2026年05月23日 15:16:19 +09:00

CASM - C-like Assembler

casm-<arch> [-DUv] files...

Overview

WARNING This project is a work in progress.

casm is an assembler with C-like syntax. It shares header files directly with C, eliminating extern declarations between C and assembly translation units. It generates a standard ELF object file with no runtime overhead.

casm supports C-like variable declarations, constants, and function definitions. It automatically generates function prologues and epilogues and maps parameter names to the registers defined by the target calling convention. Function definitions in header files are not allowed.

Each architecture is provided as a separate binary named casm-<arch>, where <arch> identifies the target, such as casm-x86_64 or casm-aarch64. This makes the target explicit and allows multiple backends to be installed side by side without conflict. The following architectures are supported:

  • AArch64
  • RISC-V 64
  • x86_64

Options

Option Description
-Dmacro[=value] Define macro with optional value
-Umacro Undefine macro
-v Display version information

Installation

Requirements:

  • POSIX-compliant Make
  • C compiler with ISO/IEC 9899:1990 (C89) support
  • C standard library with IEEE Std 1003.1-2001 (POSIX.1-2001) support
  • elf.h development header

Before building, set the ARCH variable in config.mk to the desired target architecture. The default value is aarch64.

Build from source:

$ git clone https://codeberg.org/woohyun/casm.git
$ cd casm
$ make
$ make test
# make install

To invoke casm without specifying the architecture each time, create a symbolic link named casm pointing to the installed binary for the host architecture:

# ln -s /usr/local/bin/casm-aarch64 /usr/local/bin/casm

Example

This code prints "Hello, world!" on AArch64 Linux:

const char *msg = "Hello, world!\n";
const long len = 14;
void
_start(void)
{
	mov x8, 64; /* sys_write */
	mov x0, 1; /* stdout */
	ldr x1, msg;
	ldr x1, [x1];
	ldr x2, len;
	ldr x2, [x2];
	svc #0;
	mov x8, 93; /* sys_exit */
	mov x0, 0; /* success */
	svc #0; /* does not return */
}

To assemble, link, and execute:

$ casm-aarch64 hello.s
$ ld -o hello hello.o
$ ./hello
Hello, world!

Documentation

See the following documentation for details of the CASM language:

  1. Lexical Structure
  2. Declarations
  3. Assembly Statements
  4. Functions
  5. Preprocessor

License

CASM by Woohyun Joh is released into the public domain under CC0 1.0 Universal.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.