Binary tools for ForwardCom

The following development tools are available:
High-level assembler
The assembly language for ForwardCom looks like C or Java. It understands all common operators and C-style branches and loops, as explained below.
Disassembler
The output of the disassembler can be assembled again to functional code in most cases.
Linker
The ForwardCom linker supports relinking of executable files. Other features include communal sections, function-level linking, and weak symbols.
Emulator
A ForwardCom executable program can be emulated under Windows, Linux, or other systems.
Debugger
The emulator can also be used as a debugger. There is no interactive debugging feature yet, but the debugging process produces a list of executed instructions and their results.
Library manager
The function libraries produced by the library manager can be used for both static linking, relinking, and dynamic linking.
Libraries
A standard C library includes the most common C functions, such as printf. A math library currently contains only a few functions for demonstration purposes, including trigonometric functions and numerical integration. The same mathematical functions can be used with scalars and vectors as parameters.
Code examples
A selection of code examples are provided as a starting point for experimentation (link).
Test suite
A test suite is provided for self test of a CPU (link).

The binary tools are all combined into a single executable file. The Windows version is available as forw.exe (link). Versions for Linux, Mac, and other platforms can easily be compiled from the source code (link). Everything is free and open source.

The tools can be called from a command line, batch file, shell script, or make utility. See the ForwardCom manual for instructions.

A compiler is not available yet.

High-level assembly language

Assembly language is traditionally very cryptic. Different assemblers sometimes have very different syntaxes for the same microprocessor so that it is unclear to the reader which operands are source and destination.

ForwardCom breaks this cumbersome tradition and replaces it with a clear syntax that is unambiguous and immediately intelligible to programmers. For example, adding the contents of two integer registers and storing the result in a third register is as simple as

int r1 = r2 + r3
All common operators are supported.

Branches and loops can be written in a syntax that is very similar to C or Java, with support for high-level language keywords such as: if, else, for, while, do, break, continue.

The following example shows a function to calculate a factorial. This should be easy to read even for programmers who are not familiar with assembly language:

code section execute             // define executable code section

// factorial function calculates n!
// input: r0, output: r0
_factorial function public
    if (uint64 r0 <= 20) {       // check for overflow, 64 bit unsigned integer
        uint64 r1 = 1            // start with 1
        while (uint64 r0 > 1) {  // loop through r0 values
            uint64 r1 *= r0      // multiply all values
            uint64 r0 --         // count down to 1
        }
        uint64 r0 = r1           // put result in r0
        return                   // normal return from function
    }
    int64 r0 = -1                // overflow. return max unsigned value
    return                       // return from overflow
_factorial end                   // end of function

code end                         // end of code section

While this syntax is very similar to high-level programming languages like C or Java, it differs in two important aspects: The assembly programmer must decide which registers to use for each variable, and each line must fit into a single machine instruction.

Most instructions can be predicated for conditional execution. This can be expressed conveniently by using the  ?: operator. For example, the C code  if (r1 < 0) r1 += r2;  can be coded in ForwardCom assembly as

int r0 = r1 < 0                  // r0 contains boolean result of compare
int r1 = r0 ? r1 + r2 : r1       // addition conditional on boolean r0

Code examples for inspiration can be found in the github repository (link). The complete syntax is defined in the ForwardCom manual (link).