Skip to content

kellentow/Casm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Casm Assembly Language Documentation

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.

Table of Contents

  1. Introduction
  2. Instructions
  3. Operands
  4. Creating Binaries
  5. Examples

Introduction

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.


Instructions

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

Operands

Casm uses several types of operands:

  • Registers: Denoted by rX, where X is the register number (e.g., r0, r1).
  • Pointers: Denoted by pX, where X is the address (e.g., p10).
  • Line Pointers: Denoted by plX, where Xis the line number (e.g., pl4, pl7)
  • Ram Pointers: Denoted by prX, where Xis 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.


Creating Binaries

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.


Examples

Example 1: Simple Addition

add r0 r1 r2

This instruction adds the values in r0 and r1 and stores the result in r2.

Example 2: Function Definition and Call

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.

About

My custom assembly,compiler,and cpu emulator i made

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages