[ << ] [ >> ]           [] [] [] [ ? ]

34 unSP cpu module

This chapter documents the backend for the unSP CPU architecture.


34.1 Legal

This module is written in 2021-2024 by Adrien Destugues and is covered by the vasm copyright without modifications.


34.2 General

Instructions consist of one 16-bit word, sometimes followed by a 16-bit immediate value or address.

Single byte memory accesses are not possible.

The address space is 22 bits, with a segment register which is used by adding a D: prefix to addresses (otherwise, only 16 bit addresses to the "zero page" are accessible). The segment register is adjusted automatically when a post or pre increment or decrement overflows the address register. There is also a segment register for the PC, but that does not require specific handling from the assembler at the moment (except for the presence of an LJMP instruction allowing to call code in another segment).

Conditional jump instructions in unSP are PC relative and allow to jump up to 63 instructions forward or backwards. When the code in a conditional branch is longer than this, a 2-instruction sequence is used: an opposite condition jump to PC+2, followed by a GOTO to the branch target. This is done automatically as needed by vasm if you use the "l" prefix to the jump instruction (for example LJAE instead of JAE). In this case, the long form instruction is used if necessary, and the short form is used if the target is close enough. Without the prefix, the instruction can only use the PC-relative mode and you get an assembler error if you try to jump too far.


34.3 Extensions

This backend provides the following specific extensions:


34.4 Compatibility with other assemblers and disassemblers

This backend accepts instructions in a traditional format, reusing the mnemonics from naken_asm. The official unSP documentation uses an unusual syntax, which would probably require a custom syntax module.

The closest syntax to naken_asm is the oldstyle one, but there are some differences:

The backend internally outputs data in big endian format. This is not compatible with other tools, which use little endian. The endianness can be changed at the output stage when generating a raw binary, by using vasm standard -ole command-line switch.


34.5 Known Problems

Only version 1.0 and 1.1 of the ISA is supported (they are identical as far as instruction encoding is concerned, but a few instructions have slight behavior differences). Versions 1.2 and 1.3 are backwards compatible but introduce additional instructions:

Version 2.0 is not fully compatible and introduces even more instructions.


[ << ] [ >> ]           [] [] [] [ ? ]