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 :-
|ccl||clear the carry/link bit so it isn't added in|
|ldi $42||load 42 in hex into the accumulator|
|dai $29||add hex 29 to it|
|st [result]||store it in the result memory location|
|xppc 3||return to the SCIOS ROM|
|[result] byte 0||this memory location will contain the result of the calculation|
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".
|0f20||ccl||02||Clear the Carry/Link bit|
|0f21||ldi $42||c4 42||Load the accumulator with 42 hexadecimal|
|0f23||dai $29||ec 29||decimal add 29|
|0f25||st 0f27||c8 02||save 2 on from PC|
|0f27||xppc 3||3f||return to SCIOS|
|0f28||[result]||00||result goes here|
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.