Some of you may have been following the computer tutorial series, which as of CL305 has reached the point of being at least somewhat usable for useful work.
For historical reasons, I'm naming the thing BSAC, for Bray Storage Automatic Calculator. Going forward, each 'model' number will correspond to the numbering of the save it appears in -- for example, BSAC302 supports only the ADD, SUB, HALT and NOP instructions, since CL302 added ADD and SUB.
To accompany the release of the in-game hex editor for BSAC304, I will start posting a few small programming challenges to practice writing raw machine code for this antique CPU.
I’ve been writing programs on paper with this kind of syntax:
FIBBO2
Calculates Fibbonacci numbers.
address | op ; comment
----------------------------------------------------------------
010 | T 140 ; zero out the accumulator
011 | A 015 ; acc += :one
012 | U 140 ; M[140] = 1
013 | A 015 ; acc += :one
014 | U 141 ; M[141] = 2
015 :one | X 001 ; no-op: double duty as storing the literal constant 1
016 :loop | A 140 ; acc += M[140]
017 | U 140 ; M[140] = acc
018 | A 141 ; acc += M[141]
019 | U 141 ; M[141] = acc
01a | E 012 ; if(acc > 0) goto :loop
01b | ZOnly the column under ‘op’ is actually entered into the computer,
everything else is a comment. The left-hand column shows the address of
each instruction.
Write a program which swaps two 24-bit numbers A and B, located at A=0x000 and B=0x001. By this I mean: your program should HALT with the values in 0x001 and 0x000 swapped. You may ignore any higher bits.
I'd love for the assembly opcodes to not be one letter each. May I suggest the following?
T -> MOV/LOD/SET/CPY
U -> UPD
A -> ADD
S -> SUB
X -> NOP
Z -> HLT