A Brookshear Machine implementation in Java
This project is maintained by cyberpython
BMach is a simple Java application that allows the user to edit, save and execute programs written in the simple machine language defined in Glenn Brookshear’s “Computer Science An Overview”. It supports syntax-highlighting and viewing the registers, memory cells and program counter values during program execution.
Click here to go to the downloads page.
You need to have a system with JRE 6u10+.
BMach is used like any plain text editor. After users have finished editing their code, they can click on the execute / execute step-by-step button. All instructions defined in “Computer Science An Overview” are supported. These can be entered in either binary or hexadecimal form. e.g.:
Book BMach Form
20a1 0x20a1 hexadecimal
2AFF 0x2AFF hexadecimal
5201 0101001000000001 binary
Blank lines and whitespace before and after instructions are ignored.
Single-line comments are denoted by two consecutive slashes (//
) and extend to the end of the line.
// Calculates the sum of 1 and 2 and
// stores it in register 2
0010000000000001 // alternative form: 0x2001
0010000100000010 // alternative form: 0x2102
0101001000000001 // alternative form: 0x5201
1100000000000000 // alternative form: 0xC000
// Calculates the sum of numbers 1 - 10 in register 3
0x2000 // LOAD register 0 with 0x00 (0d)
0x210A // LOAD register 1 with 0x0A (10d)
0x22FF // LOAD register 2 with 0xFF (-1d)
0x2300 // LOAD register 3 with 0x00 (0d)
0x2401 // LOAD register 4 with 0x01 (1d)
0x2501 // LOAD register 5 with 0x01 (1d)
0x2600 // LOAD register 6 with 0x00 (0d)
0xB118 // JUMP to HALT if register 1 == register 0
0x5112 // register 1 = register 1 + register 2
0x5334 // register 3 = register 3 + register 4
0x5445 // register 4 = register 4 + register 5
0xB60E // JUMP to instruction at 0x0E (0xB118)
0xC000 // HALT
// Attempts to calculate
// 127 + 1 = 128
// and causes overflow error
0x207F // 2's complement: 127
0x2101 // 2's complement: 1
0x5201 // causes overflow: 128
0xc000 // HALT
Full source code is available at this GitHub repository under the terms of the Apache License v2.0.
All icons are part of the “Silk” iconset by Mark James, except for the application icon which has been created from scratch with Inkscape.
jSyntaxPane, an open-source JEditorKit that adds support for custom syntax-highlighting to JEditorPane, is used.