Close

A Simple Test Program

A project log for Trinity

A ternary LISP machine

john-sullyJohn Sully 12/15/2014 at 08:430 Comments

No instruction set is proven until an actual program is written in it. The goal of this program is to ensure the instruction set is both useable and turing complete. The program itself is simple, it prints out its A, B, Cs, and loops back to A after printing Z.

The listing is below:

; Outputs A,B,...,Z in a continuous loop
;Setup: Loads the Loop label into IX so we can jump back to the start of the loop
Start:    LIM    Loop[0]
    SIL
    LIM    Loop[1]
    SIH
    LIM    '@'    ; 'A'-1
Loop:    SWP
    LIM    1
    ADD
    OUT
;Check if done (See if A - 'Z' == 0)
    SWP
    LIM    'Z'
    SUB
    SWP
    JAF    Z,Done   ; If the Z flag is set then jump to Done
    JIX    ; Jump to Loop
Done:    LIM    Start[0]
    SIL
    LIM    Start[1]
    SIH
    JIX
The listing shows a few intersting things about the design. First most instructions have no operands. This should greatly simplify the decoding hardware. Secondly we've introduced the strange [0] syntax to address high and low trites of our double-width registers. This is in contrast to other multi-width architectures like the Z-80 where H and L postfixes were added to the registers.

After fixing a large number of bugs in both my assembler and the emulator, the program itself worked perfectly without modification.

The output:

The assembler is output into a custom "trit" format resembling the old intel hex format. Right now my emulator reads this in directly. Eventually I hope to have a self-hosting loader in ROM that can take these files over the serial port just like my old IMSAI.

000000: 00+--+ 000+0- 	;LIM Loop[0]:(000+0-) 
0000+-: 000+++ 	        ;SIL 
0000+0: 00+--+ 000000 	;LIM Loop[1]:(000000) 
000+--: 00+--- 	                ;SIH 
000+-0: 00+--+ 0+-+0+ 	;LIM 0+-+0+ 
000+0-: 00+--0 	        ;SWP 
000+00: 00+--+ 00000+ 	;LIM 00000+ 
000++-: 000+-- 	        ;ADD 
000++0: 00+-00 	        ;OUT 
000+++: 00+--0 	        ;SWP 
00+---: 00+--+ 0+0+00 	;LIM 0+0+00 
00+-0-: 000+-0 	        ;SUB 
00+-00: 00+--0 	        ;SWP 
00+-0+: 000+-+ 000+00 0000++ 	;JAF Z[0]:(000+00) Done[0]:(0000++) 
00+-++: 000+0- 	        ;JIX 
00+0--: 00+--+ 000000 	;LIM Start[0]:(000000) 
00+00-: 000+++ 	        ;SIL 
00+000: 00+--+ 000000 	;LIM Start[1]:(000000) 
00+0+-: 00+--- 	        ;SIH 
00+0+0: 000+0- 	        ;JIX 
The assembler automatically comments the trit listing for easier debugging.

Discussions