Version 0.4 of asm359, the assembler for the GateMate System/359 project, is now available. This release brings several usability improvements, new instruction formats, and important bug fixes that were discovered during real-world testing.
Smart Instructions
The most visible addition is a set of "smart" instructions that automatically select the appropriate encoding based on operand types. Instead of choosing between LR (register-register) and L (register-memory) manually, you can now simply write LD and let the assembler figure it out:
LD R1, R2 ; Assembles as LR (2 bytes)
LD R1, [R11+100h] ; Assembles as L (4 bytes)
This pattern applies to seven common operations: LD, ADD, SUB, AND, OR, XOR, and CMP. The assembler examines the second operand—if it's a register, it emits the compact RR-format; if it's a memory reference in brackets, it emits the RX-format. This reduces cognitive load when writing code and makes the source more readable.
Shift Instructions
GMS/359 now has proper shift instructions: SHR (logical right), SHL (logical left), and SAR (arithmetic right). These use a simple 4-byte format with the shift amount encoded directly in the instruction:
SHR R4, 4 ; Shift R4 right by 4 bits
SHL R2, 8 ; Shift R2 left by 8 bits
SAR R3, 1 ; Arithmetic shift right by 1
The shift amount is limited to 0-31, which covers the useful range for 32-bit registers.
Branch Instruction Changes
A deliberate breaking change in this release: the raw BC mask, address syntax has been removed. The S/360-style explicit condition masks were error-prone—it's too easy to confuse which bit means what. Instead, the assembler now requires mnemonic aliases:
; Old (no longer accepted):
BC 4, poll_loop
BC 7, error_handler ; Wait, is 7 "not equal" or "no overflow"?
; New (required):
BB poll_loop ; Branch if Busy (CC=2)
BNE error_handler ; Branch if Not Equal (CC≠0)
This release also adds BB (Branch if Busy) and BNB (Branch if Not Busy) for I/O polling loops, which are common in GMS/359 code.
Expression Handling Fixes
Two related bugs in expression parsing were fixed. The assembler now correctly handles symbol arithmetic like:
header_ccw:
DB 01h, 00h
DW header_end - header_msg ; Calculate string length
DD header_msg
Previously, symbol - symbol expressions either failed outright or—worse—generated incorrect relocations. The fix involved two parts: first, actually parsing symbol names after the minus sign (the code had a comment saying "keep it simple for now" and just gave up), and second, recognizing that when both symbols are in the same segment, their difference is an absolute constant that needs no relocation.
Accurate Error Reporting
A subtle but important fix: error messages now report the correct source line when using %include directives. Previously, the assembler maintained its own line counter that included lines from all files, leading to confusing messages like "line 51: unknown instruction" when the actual problem was on line 83. The fix was straightforward—use the preprocessor's source location tracking instead of an independent counter.
Code Reorganization
Behind the scenes, the main assembler module was split into two files. The original assemble.c had grown to over 2,400 lines, mixing directive processing with instruction encoding. It's now divided into assemble.c (core state management, emit functions, directive processing) and asm_insns.c (GMS/359 instruction parsing and encoding). Each file is around 1,100-1,400 lines—still substantial, but more manageable.
What's Next
With the assembler toolchain stabilizing, focus shifts back to the hardware side. The shift instructions need to be implemented in the GateMate FPGA, and there's ongoing work on the cryptographic coprocessor (the test program that found several of these bugs is a modular exponentiation test for the GMS 2950).
The full source is available in the project repository. As always, bug reports and feedback are welcome.
asm359 is part of the GateMate System/359 project—a modern FPGA-based system inspired by the IBM System/360 architecture, but deliberately not binary compatible. The goal is to preserve the elegance of S/360's design while eliminating historical quirks and adapting to contemporary hardware.
No comments:
Post a Comment