Skip to content

Extensions and Limitations

dzmat edited this page Jul 19, 2019 · 4 revisions

Our emulator do not support (currently) some features which make sense only in specific hardware setup - e.g. if we do not have keyboard attached to I/O ports it is no use in KBD and ports dealing instructions.

Also note that some specific addressing features (forced by limited size of CPU registers) are not implemented. For example all conditional jumps in real CPU could work only inside 256 page of code memory. Such limitations (currently) are not repeated - so you can perform such jumps even if your code is rather long. Return stack size also is not limited to 3 cells as in original CPU.

On the other hand to make emulator more useful it allows to extend it with custom code callable with JMS instruction (call to subroutine) followed by addresses above or equal to $300. This custom code is written in Python and you can study it or add your own inventions in your copy of emulator. Let us see what custom subroutines our emulator offers out-of-the-box.

###Dumping registers and memory

You can insert these instructions everywhere in your code for debugging purpose. However, they work only in console version of emulator, they are not supported in online version.

  • JMS $3FE - prints out all memory (8 lines of 32 memory cells)
  • JMS $3FD - prints out first 64 cells of memory (4 lines of 16 cells)
  • JMS $3FF - prints out all registers, accumulator and carry flag

So for example if you run the test program from examples, you will get the output shown below:

$ python main.py examples/test.asm 8
1 0 4 2 0 0 0 0 0 0 0 0 0 0 0 0
acc=0, cy=1, ip=22

Here the first line (1 0 4 2 0...) contains the values of 16 registers and the second shows the state of Accumulator, Carry flag and Instruction pointer.

###Console Input and Output

These subroutines allow you to use emulator as a tiny scripting language processor - to run small utilities etc.

  • JMS $3E0 prints the character to console, using register pair r2:r3 as an ASCII code
  • JMS $3F0 reads the character from console, storing its code in r2:r3.

These instructions work in online emulator also, though you should provide some input to them instead of 16 digits of initial register values. For example let us try the following code:

jms $3f0    ; read the character into r2:r3
inc r3      ; increment its ascii-code by 1
jms $3e0    ; write the character to output

Try this - but do not forget to remove zeroes from "input" and instead type, for example, letter A here. After running the example you will see letter B in the output. Try other letters - and you will soon came to idea that it could be used to build Caesar's Cipher machine :)

There are also other examples provided with sources. Of them toupper.asm converts the line from the console into uppercase while strrev.asm shows how to print the line in reverse (storing it temporarily in the external memory).


Next: Running Console Emulator