How to program the Science of Cambridge MK14
This little primer shows how to write a program for the Science of Cambridge MK14. The same program is written twice. Once, in old fashioned mode, by using the MK14 Keyboard, and again, using the TASM assembler.
Note : since this was first written the emulator has been redesigned so it starts up running. The "press F9" step to kick it off is no longer required.
The program is very simple. We want to perform the following calculation :
Add 29 to 42 and store the result in a memory location.
I know it isn't very exciting, but the point of this document is to get the MK14 working, not to write thrilling programs. We use the following program :-
In olden days, the next stage was to convert this to machine code. This was done by hand. Our program will start at memory location $F20, as $F00..$F11 are used by the SCIOS ROM "Operating System".
The only thing requiring explanatin is the store instruction. This is "PC Relative", so +2 means 2 on from the Program Counter. 0F26 (where the offset is) +2 gives you 0F28, where the result goes.
Technical Note: Unlike almost all other CPUs, the PC (Pointer 0) is incremented before the instruction is fetched, so when the ST instruction is being executed, the PC points to 0F26 and not 0F27 as you would expect on most other processors.
Entering and running the program
Run the MK14 emulator, by typing MK14 at the command line , or by clicking on the application in Windows. It will boot up in debug mode. If you press F9 to run the emulator, the debug display will "fuzz" and the 0000 00 display will come up.
To check it, press Z (ABORT) to return to Address mode, and enter 0 F 2 0 again. You can use the M(EM) button to step through the program showing each byte in turn.
To run the program, press Z(ABORT) to go into address mode. Enter the start program address 0 F 2 0. The display should read 0F20 02. Press G to run the program. The instructions are run. On exit, the address is set to the address after the XPPC 3 instruction, which is the result byte at 0F28. If all has worked correctly it should display 0F28 71.
Using the Assembler
It is much quicker to use the shareware assembler TASM (do a web search for TASM301.ZIP or TASM69.ZIP) and the SC/MP 'table' TASM8060.TAB, available from the MK14 website. We shall repeat the excercise again, but using the assembler to generate the program.
Enter the following instructions into a file test.asm (not the list markers :) )
The emulator expects files to load at 0F00h, but our program is starting as before at 0F20h. The two 'orgs' are required to get the format right. Memory below 0F12 is not available for programs, it is used by the SCIOS ROM.
Assemble the program using tasm -t8060 -b test.asm test.bin test.lst
This produces a binary file test.bin, and a listing file test.lst
Run the MK14 emulator but use MK14 TEST.BIN, or , from windows, drop the TEST.BIN file on the MK14.COM icon. This will load it. You can examine the code in the debugger by typing 0 F 2 0.
To run the program, press F9 to start the emulator, then press 0 F 2 0 G(O) as before, and the program will run.