Casm is a low-level assembly language designed for programming a custom CPU architecture. The language features basic operations, conditional jumps, function definitions, and custom operations like arithmetic and bitwise shifts.
Casm is designed to provide a simple yet powerful assembly language for custom CPU implementations. The language allows direct manipulation of registers, memory, and control flow to achieve a variety of tasks, such as computation, input/output operations, and conditional execution.
x/XY | 0Y | 1Y | 2Y | 3Y | 4Y | 5Y | 6Y | 8Y | 9Y | AY | BY | CY | DY | EY | FY |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
X0 | Jump | Return | Exit | Read | Write | P==P? | P==0? | R==R | P==0? | Nop | None | None | None | None | None |
X1 | Left bitshft | Right bitshft | Add | Sub | Mult | Div | Reg1 += 1 | None | None | Reg left shft | Reg right shft | Reg add | Reg Sub | Reg Mult | Reg Div |
Casm uses several types of operands:
- Registers: Denoted by
rX
, whereX
is the register number (e.g.,r0
,r1
). - Pointers: Denoted by
pX
, whereX
is the address (e.g.,p10
). - Line Pointers: Denoted by
plX
, whereX
is the line number (e.g.,pl4
,pl7
) - Ram Pointers: Denoted by
prX
, whereX
is the address starting in ram (e.g.,pr70
,pr8
) - Labels/Functions: Functions are defined with the
def
keyword, and run instructions can target them.
Operands for instructions must be provided in the correct order as per the instruction format.
To compile your Casm code into binary form, use the following Python script:
python3 compiler.py <filename>
This will take the Casm source code file, convert it to binary, and save it with a .bin
extension.
add r0 r1 r2
This instruction adds the values in r0
and r1
and stores the result in r2
.
def my_function
add r0 r1 r2
return
run my_function
This code defines a function my_function
that adds r0
and r1
, stores the result in r2
, and then returns. The run
instruction calls my_function
.
For more information, consult the Casm source code.