kMouse uses a serial port for user I/O. The serial port is configured for 57600 bps 8N1. A terminal emulator program such as TeraTerm can be used on a PC to communicate with the PIC18. For testing, a PIC18LF2620 was used. The interpreter is self contained and only needs a program to communicate on a serial port and send a file. Practically any computer with a serial port (or USB with adapter e.g. FTDI cable) can be used.
Command Interface
kMouse has a command line interface which provides two functions: load a program, run a program. The user prompt is a period (.). Invalid commands and errors are indicated by '!' sent to the terminal.
To load a program:
At the prompt type 'L' or 'l' (lower case is allowed).
A response of ':' will appear to indicate the loader is ready. A text file containing the source can then be sent. (in TeraTerm File->Send File...)
The loader will accept the source file and compress the program removing comments, blank space, etc. It also fills out a label table with jump positions. (Because of the loader compression, a kMouse program can be written with comments and white space for readability without suffering a performance penalty.)
While loading, a series of asterisks (*) will be displayed to show progress.
When the loader is complete, the prompt (.) will return.
To run a program:
At the prompt, type 'G' or 'g'. (for “go”)
A new line will be sent and the program will run. If a program has not been loaded, a '!' is printed and the prompt returned. If a label is undefined, a '!' will also be printed.
When the program reaches the end command (see below), it will return to the command prompt.
To stop a program while it is running send a control-C (^C) and the command prompt will return.
The interpreter only operates on a single program. When a program is loaded, it overwrites the previous program.
Syntax
The syntax of kMouse uses single characters for commands and hexadecimal numbers. The syntax is explained below.
kMouse is a stack based language (like Forth) so all operations are post fix. This is shown below in the syntax and examples. The stack can hold up to 16 words (16 bit values)
There are 26 variables which are lower case letters (a – z)
There are 26 labels which are upper case letters (A -Z)
All numbers are in hexadecimal and must be preceded with an '&'. (The interpreter can handle different length values. i.e. there can be 1 to 4 characters in a number)
The program has a defined format. There is a separation between the main program and the macro (subroutine) definitions. The '%' symbol indicates the program stop. A set of two '$'s indicates the end of the source code. The format is:
< Main program >
%
< Macro (subroutine) Definitions >
$$
Operation |
Syntax |
Example |
Top of Stack Value |
Assign a value to a variable |
: |
&1234 a : |
< no change > |
Write a byte to a register |
| |
&55 &0F80 | |
< no change > |
Put the contents of a variable on the stack |
. |
a . |
<contents of variable 'a'> |
Read a byte, place 16 bit value on stack |
, |
&0F80 , |
<contents of register &0F80 |
Add the top two values , leave result on stack |
+ |
&12 &34 + |
&0046 |
Subtract the top two values, leave result on stack |
- |
&46 &34 - |
&0012 |
Put the value of an ASCII character on the stack |
' |
'c |
&0043 |
Conditional Equal |
= |
&5 &6 = |
0 if False, 1 if True |
Conditional Less Than |
< |
&5 &6 < |
0 if False, 1 if True |
Conditional Greater Than |
> |
&5 &6 > |
0 if False, 1 if True |
If / Endif if value on stack is > 0, execute between [ and ] if value on stack is ≤ 0, skip to after ] |
[ … ] |
&1... |