Swiftpack.co - loyihsu/Gamma16 as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
💻 An emulator written in Swift of a legacy version of Sigma16.
.package(url: "https://github.com/loyihsu/Gamma16.git", from: "v0.1.7")


An emulator written in Swift of a legacy version of Sigma16.

This is an emulator written in Swift to emulate the behaviour of Sigma16 assembler and emulator. The project contains two parts, the Gamma16Core, where the emulator, parser, and assembler are impletemented. The other part is Gamma16Cli, the command line tool.

Sigma16 (v0.1.7) is used in Systems & Networks course at University of Glasgow (thus, the project name, Gamma16).

How to use it

Get the Binary

Checkout the Releases

Some OSes and architectures have precompiled binaries released under the Release section of this repository.

Build the Project

If your OS is not listed in the Release section, or you prefer to build this project yourself, you can easily do it. This is especially recommended if you have Swift installed on your system.

This program was built entirely with Swift and Swift Package, any OS with Swift 5 and Swift Package support can build and run the program.

With Swift installed, building the project is as easy as running make command in the project directory in Terminal:

git clone https://github.com/loyihsu/gamma16
cd gamma16

Use Gamma16Cli


To assemble and show the results of assembling, with the Assembly source code named, for instance, test.txt, you can run:

gamma16-cli assemble --file test.txt


To step the code automatically, you can run:

gamma16-cli autorun --file test.txt

You can also specify interval:

gamma16-cli autorun --file test.txt --interval 1

The example here will step your code with 1 second interval.

You can also specify the minimum rows of memory to be shown by adding a --memory option:

gamma16-cli autorun --file test.txt --memory 10

This example will ask the program print at least 10 rows from memory.


You can also manually step through the code with:

gamma16-cli step --file test.txt

You can also specify the minimum rows of memory to be shown by adding a --memory option:

gamma16-cli step --file test.txt --memory 10

This example will ask the program print at least 10 rows from memory.

This command will allow you to step through your code with the RETURN/ENTER key.

Supported Sigma16 Syntax

RRR Instructions

All RRR instructions take three operands, Rd,Ra,Rb. The machine code format is opcode,d,a,b.

Opcode Mnemonic Action
0 add Rd = Ra + Rb
1 sub Rd = Ra - Rb
2 mul Rd = Ra * Rb
3 div Rd = Int(Ra / Rb), R15 = Ra % Rb
4 cmplt Rd = (Ra < Rb)
5 cmpeq Rd = (Ra == Rb)
6 cmpgt Rd = (Ra > Rb)
7 inv Rd = ~Ra (Rd = NOT Ra)
8 and Rd = Ra & Rb (Rd = Ra AND Rb)
9 or Rd = Ra | Rb (Rd = Ra OR Rb)
a xor Rd = Ra ^ Rb (Rd = Ra XOR Rb)
b shiftl Rd = Ra << Rb (Rd = Ra shift left by Rb)
c shiftr Rd = Ra >> Rb (Rd = Ra shift right by Rb)
d trap Calling OS interrupt handler
Calling trap R0,R0,R0 will halt the program

RX Instructions

All RX instructions have the same opcode of f. The machine code format is still opcode,d,a,b. b will be utilised to recognise which command it is. All RX instructions take two machine words, the first word is the command, and the second is the x address or value.

Jump Instruction

The jump instruction is a special type of RX instruction. The operand it takes is in the format of x[Ra].

Opcode b Mnemonic Action
f 3 jump pc = x + Ra

Other Instructions

All other RX commands takes the operands format of Rd,x[Ra]

Opcode b Mnemonic Action
f 0 lea Rd = x + Ra
f 1 load Rd = memory[x+Ra]
f 2 store memory[x+Ra] = Rd
f 4 jumpf if Rd == 0 (false), pc = x+Ra
f 5 jumpt if Rd != 0 (false), pc = x+Ra
f 6 jal Rd = pc, pc = x+Ra

Data Statements

Each data statement will be led by a label, data, and then the content of the data. For instance: X data 100 will allocate a memory location, create a symbol X, and store the data, 100, in the memory location. This step will be done at the assemble stage.


Numbers are in decimals. With $ and 4 hex digits you can also specify hexidecimal numbers. For instance X data $00ff will be evaluated the same as X data 255.


The Gamma16 project was originally written by Yu-Sung Loyi Hsu in Swift as part of a project to emulate the Sigma16 (v0.1.7) assembler and emulator natively on macOS within the scope of teaching of the Systems & Networks course at University of Glasgow.

The Sigma16 language is designed by John O’Donnell and the latest version implementaions can be found at the Github repository of Sigma16.


This project is licensed under MIT.


Stars: 2
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

17 weeks ago

This is the release of the Gamma16 CLI program.

Operating Systems

For macOS

  1. If you are using macOS for 64-bit Intel, choose macos-x86_64.
  2. If you are using macOS for Apple Silicon, choose macos-arm64.

For Linux

  1. If you are using an Linux distro like Linux Arch or Ubuntu on 64-bit Intel CPU, choose linux-x86_64.

The pre-built binary of v0.1.7 release for arm64 Linux versions is not available due to some issues. It may be available in the future. In the meantime, you can either Build the Project route or use the previous beta release below.

For Windows

As the build tool for Windows is not yet available, the Windows binaries are not available yet. Windows users can use the original S16 app, or try to use Linux variants via Linux subsystem.

First Time Users

If you haven't used binary files before, you can run the binary by

  1. to run it without installation, use ./gamma16-cli in the downloaded and unzipped directory.
  2. use install ./gamma16-cli /usr/local/bin/gamma16-cli in the directory to install the file to your system, so you can directly run gamma16-cli without the limit of which directory you are in.


  1. The Linux binaries are built as static executable, which allows it to be run without requiring Swift to be installed.
  2. macOS Swift doesn't support such option. However, if you are running macOS Mojave 10.14.4 or later, you are not likely to run into a problem because the libraries are included in the OS.
  3. If you run into an installation problem, it can almost always be solved by installing Swift on your system.
  4. It is recommended if you have Swift on your system to Build the Project from source code.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics