Close
0%
0%

kMouse Programming Language Interpreter

kMouse is a programming language created for the 1kB challenge based on the Mouse language created by Peter Grogono

Similar projects worth following
kMouse is an interpreted language running on a PIC18 microcontroller. It is a simplified variant (to fit in 1kB) of the programming language Mouse created by Peter Grogono in the 1970s. One way to think about it is that kMouse is to Mouse as Tiny BASIC is to BASIC.

The goal of Mouse was to have a language designed to fit in small memory systems. kMouse was created in that same spirit. More information about Mouse can be found at : http://mouse.davidgsimpson.com/
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 pre

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...

Read more »

1kB_challenge_sch.pdf

Schematic for testing

Adobe Portable Document Format - 15.94 kB - 01/06/2017 at 02:00

Preview

kMouse.X.zip

Microchip MPLABX project files

x-zip-compressed - 47.75 kB - 01/06/2017 at 02:00

Download

kMouse.lst

Assembly listing of the interpreter

plain - 96.35 kB - 01/06/2017 at 02:00

Download

kMouse Guide.pdf

A guide to using kMouse and writing programs

Adobe Portable Document Format - 142.40 kB - 01/06/2017 at 02:00

Preview

kMouse.asm

Assembly Source

plain - 27.95 kB - 01/06/2017 at 02:00

Download

View all 6 files

  • 1 × PIC18LF2620 Microcontroller
  • 1 × FTDI TTL-323R -5.0V USB to TTL serial cable
  • 1 × LEDs Electronic Components / Misc. Electronic Components

  • It's working!

    David Hunter01/06/2017 at 02:11 0 comments

    I was able to get the interpreter working and tested this week. The picture shows the test program on the left and the terminal output on the right. Unfortunately, I couldn't show the LED blinking, but that is what the "on" and "off" messages indicate.

    This was a lot of fun and sometimes quite a puzzle fitting a language interpreter into 1kB. I had to reach into my old "bag of tricks" to get the code down. Early in my career, I needed to fit code in small spaces and it was really great fun to be able to "dust off" the old techniques again. I hope this project inspires others to what can be done in small spaces.

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates