Name Last Update
..
README.md Loading commit data...
writing.md Loading commit data...

Using Kasm

The Kasm assembler is included as part of the Kcpu project. No additional build steps are required to use Kasm.

The assembler can be invoked with a simple command line argument:

java -jar target/kcpu-1.0-SNAPSHOT.jar -kasm

Alternatively, there is a script provided:

./kasm.sh

To view the available command line arguments:

./kasm.sh -h

Which will display:

usage: kasm [options] [kasm ...]
 -b,--base <addr>     Program's base address.  Emitted code will assume it
                      is loaded to this address.
 -c,--cpu             Displays suppoted CPU opcodes
 -h,--help            Shows this help.
    --kasm            This option is ignored.
 -m,--mcu             Displays suported MCU opcodes.
 -o,--output <file>   Filename to use for building a single output file.
 -v,--verbose         Verbose output.
Non-KASM files may be ignored.

Compiling Kasm Programs

After writing a Kasm program, it is necessary to compile it so it can be run in Kcpu. The simplest way to do this is to just invoke Kasm and tell it which files to compile.

./kasm.sh test.kasm

You can use the -v or --verbose options for verbose output. It will display the names of each input and output file, as well as display a textual representation of the compiled code as it moves along.

./kasm.sh -v test.kasm

Will display something similar to this:

Input : /Users/jlhawkwell/Projects/kcpu/test.kasm
Output: /Users/jlhawkwell/Projects/kcpu/test.kc
[      MOVS] 1100  : 0702  -> 0000 0200
[       ADD] 0100  : 0102  -> 0000 1000
[       ADD] 0100  : 0102  -> 0200 0100
[      MOVS] 1100  : 0702  -> 0000 0200
[       JDL] 28ff  : 0103  -> 0000 0002 2a00
[      DEVA] 00ff  : 0001  -> 0000
[      DEVA] 00ff  : 0001  -> 0100
[       GPC] 1bff  : 0000  ->
[       GPC] 1bff  : 0201  -> 0004

The columns are, in the following order: [Instruction] opcode : reference -> arguments The reference column is automatically generated. The reference value tells the processor how many arguments there are and how to store or load each one. It is directly correlated to the argument types specified in the assembly code.

By default, Kasm will produce exactly one binary for each input source file. Optionally, you can have all source files built into a single binary by using the -o option.

./kasm.sh -o output.kc rom1.kasm rom2.kasm rom3.kasm

This command will compile the source files in the specified order and write out all the machine code to output.kc

Writing Kasm Programs

Writing Kasm programs is a fairly involved process, as assembly language(s) generally are. For information on writing Kasm programs, see Writing Kasm