2015-10-16 14:36:56 +00:00
|
|
|
SixtyPical
|
2015-10-16 08:30:24 +00:00
|
|
|
==========
|
|
|
|
|
2018-03-27 11:36:33 +00:00
|
|
|
This document describes the SixtyPical programming language version 0.15,
|
2018-02-05 13:17:23 +00:00
|
|
|
both its static semantics (the capabilities and limits of the static
|
|
|
|
analyses it defines) and its runtime semantics (with reference to the
|
|
|
|
semantics of 6502 machine code.)
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
This document is nominally normative, but the tests in the `tests` directory
|
|
|
|
are even more normative.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
Refer to the bottom of this document for an EBNF grammar of the syntax of
|
|
|
|
the language.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Types
|
|
|
|
-----
|
|
|
|
|
2018-02-07 14:48:55 +00:00
|
|
|
There are five *primitive types* in SixtyPical:
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
* bit (2 possible values)
|
|
|
|
* byte (256 possible values)
|
2017-11-17 16:56:52 +00:00
|
|
|
* word (65536 possible values)
|
2015-10-18 18:41:26 +00:00
|
|
|
* routine (code stored somewhere in memory, read-only)
|
2017-12-01 13:09:25 +00:00
|
|
|
* pointer (address of a byte in a buffer)
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2018-02-07 14:48:55 +00:00
|
|
|
There are also three *type constructors*:
|
2017-11-20 16:14:17 +00:00
|
|
|
|
2018-03-05 10:38:20 +00:00
|
|
|
* T table[N] (N entries, 1 ≤ N ≤ 256; each entry holds a value
|
2018-02-07 14:48:55 +00:00
|
|
|
of type T, where T is `byte`, `word`, or `vector`)
|
2018-02-16 09:51:24 +00:00
|
|
|
* buffer[N] (N entries; each entry is a byte; 1 ≤ N ≤ 65536)
|
2018-02-07 14:48:55 +00:00
|
|
|
* vector T (address of a value of type T; T must be a routine type)
|
|
|
|
|
|
|
|
### User-defined ###
|
|
|
|
|
|
|
|
A program may define its own types using the `typedef` feature. Typedefs
|
|
|
|
must occur before everything else in the program. A typedef takes a
|
|
|
|
type expression and an identifier which has not previously been used in
|
|
|
|
the program. It associates that identifer with that type. This is merely
|
|
|
|
a type alias; two types with different names will compare as equal.
|
2017-11-20 16:14:17 +00:00
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Memory locations
|
|
|
|
----------------
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
A primary concept in SixtyPical is the *memory location*. At any given point
|
|
|
|
in time during execution, each memory location is either *uninitialized* or
|
|
|
|
*initialized*. At any given point in the program text, too, each memory
|
2015-10-16 08:30:24 +00:00
|
|
|
location is either uninitialized or initialized. Where-ever it is one or
|
|
|
|
the other during execution, it is the same in the corresponding place in
|
|
|
|
the program text; thus, it is a static property.
|
|
|
|
|
|
|
|
There are four general kinds of memory location. The first three are
|
|
|
|
pre-defined and built-in.
|
|
|
|
|
|
|
|
### Registers ###
|
|
|
|
|
|
|
|
Each of these hold a byte. They are initially uninitialized.
|
|
|
|
|
|
|
|
a
|
|
|
|
x
|
|
|
|
y
|
|
|
|
|
|
|
|
### Flags ###
|
|
|
|
|
|
|
|
Each of these hold a bit. They are initially uninitialized.
|
|
|
|
|
|
|
|
c (carry)
|
|
|
|
z (zero)
|
|
|
|
v (overflow)
|
|
|
|
n (negative)
|
|
|
|
|
|
|
|
### Constants ###
|
|
|
|
|
|
|
|
It may be strange to think of constants as memory locations, but keep in mind
|
2015-10-16 14:36:56 +00:00
|
|
|
that a memory location in SixtyPical need not map to a memory location in the
|
|
|
|
underlying hardware. All constants are read-only. Each is initially
|
|
|
|
initialized with the value that corresponds with its name.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
They come in bit and byte types. There are two bit constants,
|
|
|
|
|
|
|
|
off
|
|
|
|
on
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
two hundred and fifty-six byte constants,
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
...
|
|
|
|
255
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
and sixty-five thousand five hundred and thirty-six word constants,
|
|
|
|
|
2017-11-20 15:18:21 +00:00
|
|
|
word 0
|
|
|
|
word 1
|
2017-11-17 16:56:52 +00:00
|
|
|
...
|
2017-11-20 15:18:21 +00:00
|
|
|
word 65535
|
2017-11-17 16:56:52 +00:00
|
|
|
|
2017-11-20 15:18:21 +00:00
|
|
|
Note that if a word constant is between 256 and 65535, the leading `word`
|
|
|
|
token can be omitted.
|
2017-11-17 16:56:52 +00:00
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### User-defined ###
|
|
|
|
|
|
|
|
There may be any number of user-defined memory locations. They are defined
|
2017-11-17 16:56:52 +00:00
|
|
|
by giving the type (which may be any type except `bit` and `routine`) and the
|
2015-10-18 18:41:26 +00:00
|
|
|
name.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
byte pos
|
|
|
|
|
2016-06-16 16:02:13 +00:00
|
|
|
An address in memory may be given explicitly on a user-defined memory location.
|
2015-10-18 15:22:36 +00:00
|
|
|
|
2015-10-18 18:41:26 +00:00
|
|
|
byte table screen @ 1024
|
2015-10-18 15:22:36 +00:00
|
|
|
|
2016-06-16 16:02:13 +00:00
|
|
|
Or, a user-defined memory location may be given an initial value. But in this
|
|
|
|
case, an explicit address in memory cannot be given.
|
|
|
|
|
2016-06-16 16:03:31 +00:00
|
|
|
byte pos : 0
|
2016-06-16 16:02:13 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
A user-defined vector memory location is decorated with `inputs`, `outputs`
|
|
|
|
and `trashes` lists like a routine (see below), and it may only hold addresses
|
|
|
|
of routines which are compatible. (Meaning, the routine's inputs (resp. outputs,
|
|
|
|
trashes) must be a subset of the vector's inputs (resp. outputs, trashes.))
|
2015-10-19 12:04:08 +00:00
|
|
|
|
2018-02-07 14:48:55 +00:00
|
|
|
vector routine
|
|
|
|
inputs a, score
|
|
|
|
outputs x
|
|
|
|
trashes y
|
|
|
|
actor_logic @ $c000
|
2015-10-19 12:04:08 +00:00
|
|
|
|
2017-11-20 16:14:17 +00:00
|
|
|
Note that in the code of a routine, if a memory location is named by a
|
|
|
|
user-defined symbol, it is an address in memory, and can be read and written.
|
|
|
|
But if it is named by a literal integer, either decimal or hexadecimal, it
|
|
|
|
is a constant and can only be read (and when read always yields that constant
|
|
|
|
value. So, for instance, to read the value at `screen` above, in the code,
|
|
|
|
you would need to reference the symbol `screen`; attempting to read 1024
|
|
|
|
would not work.
|
|
|
|
|
|
|
|
This is actually useful, at least at this point, as you can rely on the fact
|
|
|
|
that literal integers in the code are always immediate values. (But this
|
|
|
|
may change at some point.)
|
2017-11-20 14:10:43 +00:00
|
|
|
|
2017-12-01 13:09:25 +00:00
|
|
|
### Buffers and Pointers ###
|
|
|
|
|
|
|
|
Roughly speaking, a `buffer` is a table that can be longer than 256 bytes,
|
|
|
|
and a `pointer` is an address within a buffer.
|
|
|
|
|
|
|
|
A `pointer` is implemented as a zero-page memory location, and accessing the
|
|
|
|
buffer pointed to is implemented with "indirect indexed" addressing, as in
|
|
|
|
|
|
|
|
LDA ($02), Y
|
|
|
|
STA ($02), Y
|
|
|
|
|
2018-02-08 11:58:24 +00:00
|
|
|
There are extended instruction modes for using these types of memory location.
|
2017-12-01 13:09:25 +00:00
|
|
|
See `copy` below, but here is some illustrative example code:
|
|
|
|
|
|
|
|
copy ^buf, ptr // this is the only way to initialize a pointer
|
|
|
|
add ptr, 4 // ok, but only if it does not exceed buffer's size
|
|
|
|
ld y, 0 // you must set this to something yourself
|
|
|
|
copy [ptr] + y, byt // read memory through pointer, into byte
|
|
|
|
copy 100, [ptr] + y // write memory through pointer (still trashes a)
|
|
|
|
|
|
|
|
where `ptr` is a user-defined storage location of `pointer` type, and the
|
|
|
|
`+ y` part is mandatory.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Routines
|
|
|
|
--------
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Every routine must list all the memory locations it *reads from*, which we
|
|
|
|
call its `inputs`, and all the memory locations it *writes to*. The latter
|
|
|
|
we divide into two groups: its `outputs` which it intentionally initializes,
|
|
|
|
and its `trashes`, which it does not care about, and leaves uninitialized.
|
|
|
|
For example, if it uses a register to temporarily store an intermediate
|
|
|
|
value used in a multiplication, that register has no meaning outside of
|
|
|
|
the multiplication, and is one of the routine's `trashes`.
|
|
|
|
|
|
|
|
It is common to say that the `trashes` are the memory locations that are
|
|
|
|
*not preserved* by the routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
routine foo
|
|
|
|
inputs a, score
|
|
|
|
outputs x
|
|
|
|
trashes y {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
The union of the `outputs` and `trashes` is sometimes collectively called
|
|
|
|
"the WRITES" of the routine, for historical reasons and as shorthand.
|
2017-11-17 16:56:52 +00:00
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Routines may call only routines previously defined in the program source.
|
2015-10-20 08:33:30 +00:00
|
|
|
Thus, directly recursive routines are not allowed. (However, routines may
|
|
|
|
also call routines via vectors, which are dynamically assigned. In this
|
|
|
|
case, there is, for the time being, no check for recursive calls.)
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
For a SixtyPical program to be run, there must be one routine called `main`.
|
|
|
|
This routine is executed when the program is run.
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
The memory locations given as inputs to a routine are considered to be initialized
|
2015-10-16 14:36:56 +00:00
|
|
|
at the beginning of the routine. Various instructions cause memory locations
|
|
|
|
to be initialized after they are executed. Calling a routine which trashes
|
|
|
|
some memory locations causes those memory locations to be uninitialized after
|
|
|
|
that routine is called. At the end of a routine, all memory locations listed
|
2017-11-17 16:56:52 +00:00
|
|
|
as outputs must be initialized.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
A literal word can given instead of the body of the routine. This word is the
|
|
|
|
absolute address of an "external" routine located in memory but not defined by
|
|
|
|
the SixtyPical program.
|
2015-10-17 12:50:21 +00:00
|
|
|
|
|
|
|
routine chrout
|
|
|
|
inputs a
|
|
|
|
trashes a
|
|
|
|
@ 65490
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Instructions
|
|
|
|
------------
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Instructions are inspired by, and in many cases closely resemble, the 6502
|
|
|
|
instruction set. However, in many cases they do not map 1:1 to 6502 instructions.
|
|
|
|
If a SixtyPical instruction cannot be translated validly to one more more 6502
|
|
|
|
instructions while retaining all the stated constraints, that's a static error
|
|
|
|
in a SixtyPical program, and technically any implementation of SixtyPical, even
|
|
|
|
an interpreter, should flag it up.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### ld ###
|
|
|
|
|
2015-10-18 18:02:07 +00:00
|
|
|
ld <dest-memory-location>, <src-memory-location> [+ <index-memory-location>]
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
Reads from src and writes to dest.
|
|
|
|
|
|
|
|
* It is illegal if dest is not a register.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
* It is illegal if src is not of same type as dest (i.e., is not a byte.)
|
|
|
|
* It is illegal if src is uninitialized.
|
|
|
|
|
|
|
|
After execution, dest is considered initialized. The flags `z` and `n` may be
|
2017-11-17 16:56:52 +00:00
|
|
|
changed by this instruction; they must be named in the WRITES, and they
|
2015-10-16 14:36:56 +00:00
|
|
|
are considered initialized after it has executed.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-18 18:02:07 +00:00
|
|
|
If and only if src is a byte table, the index-memory-location must be given.
|
2018-03-26 12:16:53 +00:00
|
|
|
In this case, it is illegal if the value of the index-memory-location falls
|
|
|
|
outside of the range of the table.
|
2015-10-18 18:02:07 +00:00
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Some combinations, such as `ld x, y`, are illegal because they do not map to
|
2018-03-26 12:16:53 +00:00
|
|
|
underlying opcodes. (For an instruction which maps more flexibly to underlying
|
|
|
|
opcodes, see `copy`.)
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2018-02-08 11:58:24 +00:00
|
|
|
There is another mode of `ld` which reads into `a` indirectly through a pointer.
|
|
|
|
|
2018-02-09 11:23:18 +00:00
|
|
|
ld a, [<src-memory-location>] + y
|
2018-02-08 11:58:24 +00:00
|
|
|
|
|
|
|
The memory location in this syntax must be a pointer.
|
|
|
|
|
|
|
|
This syntax copies the contents of memory at the pointer (offset by the `y`
|
|
|
|
register) into a register (which must be the `a` register.)
|
|
|
|
|
|
|
|
In addition to the constraints above, `y` must be initialized before
|
|
|
|
this mode is used.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### st ###
|
|
|
|
|
2015-10-18 18:02:07 +00:00
|
|
|
st <src-memory-location>, <dest-memory-location> [+ <index-memory-location>]
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
Reads from src and writes to dest.
|
|
|
|
|
|
|
|
* It is illegal if dest is a register or if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
* It is illegal if src is not of same type as dest.
|
|
|
|
* It is illegal if src is uninitialized.
|
|
|
|
|
|
|
|
After execution, dest is considered initialized. No flags are
|
|
|
|
changed by this instruction (unless of course dest is a flag.)
|
|
|
|
|
2015-10-18 18:02:07 +00:00
|
|
|
If and only if dest is a byte table, the index-memory-location must be given.
|
2018-03-26 12:16:53 +00:00
|
|
|
In this case, it is illegal if the value of the index-memory-location falls
|
|
|
|
outside of the range of the table.
|
2015-10-18 18:02:07 +00:00
|
|
|
|
2018-02-09 11:23:18 +00:00
|
|
|
There is another mode of `st` which write `a` into memory, indirectly through
|
|
|
|
a pointer.
|
|
|
|
|
|
|
|
st a, [<dest-memory-location>] + y
|
|
|
|
|
|
|
|
The memory location in this syntax must be a pointer.
|
|
|
|
|
|
|
|
This syntax copies the constents of the `a` register into
|
|
|
|
the contents of memory at the pointer (offset by the `y` register).
|
|
|
|
|
|
|
|
In addition to the constraints above, `y` must be initialized before
|
|
|
|
this mode is used.
|
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
### copy ###
|
|
|
|
|
|
|
|
copy <src-memory-location>, <dest-memory-location>
|
|
|
|
|
|
|
|
Reads from src and writes to dest. Differs from `st` in that is able to
|
|
|
|
copy more general types of data (for example, vectors,) and it trashes the
|
|
|
|
`z` and `n` flags and the `a` register.
|
|
|
|
|
|
|
|
* It is illegal if dest is read-only.
|
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
|
|
|
* It is illegal if src is not of same type as dest.
|
|
|
|
* It is illegal if src is uninitialized.
|
|
|
|
|
|
|
|
After execution, dest is considered initialized, and `z` and `n`, and
|
|
|
|
`a` are considered uninitialized.
|
|
|
|
|
2017-12-01 13:09:25 +00:00
|
|
|
There are two extra modes that this instruction can be used in. The first is
|
|
|
|
to load an address into a pointer:
|
|
|
|
|
|
|
|
copy ^<src-memory-location>, <dest-memory-location>
|
|
|
|
|
|
|
|
This copies the address of src into dest. In this case, src must be
|
|
|
|
of type buffer, and dest must be of type pointer. src will not be
|
|
|
|
considered a memory location that is read, since it is only its address
|
|
|
|
that is being retrieved.
|
|
|
|
|
|
|
|
The second is to read or write indirectly through a pointer.
|
|
|
|
|
|
|
|
copy [<src-memory-location>] + y, <dest-memory-location>
|
|
|
|
copy <src-memory-location>, [<dest-memory-location>] + y
|
|
|
|
|
|
|
|
In both of these, the memory location in the `[]+y` syntax must be
|
|
|
|
a pointer.
|
|
|
|
|
|
|
|
The first copies the contents of memory at the pointer (offset by the `y`
|
|
|
|
register) into a byte memory location.
|
|
|
|
|
|
|
|
The second copies a literal byte, or a byte memory location, into
|
|
|
|
the contents of memory at the pointer (offset by the `y` register).
|
|
|
|
|
|
|
|
In addition to the constraints above, `y` must be initialized before
|
|
|
|
this mode is used.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### add dest, src ###
|
|
|
|
|
|
|
|
add <dest-memory-location>, <src-memory-location>
|
|
|
|
|
|
|
|
Adds the contents of src to dest and stores the result in dest.
|
|
|
|
|
|
|
|
* It is illegal if src OR dest OR c is uninitialized.
|
|
|
|
* It is illegal if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n, z, c, and v flags, requiring that they be in the WRITES,
|
2015-10-16 14:36:56 +00:00
|
|
|
and initializing them afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
dest and src continue to be initialized afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-12-07 15:34:06 +00:00
|
|
|
In addition, if dest is of `word` type, then src must also be of `word`
|
|
|
|
type, and in this case this instruction trashes the `a` register.
|
|
|
|
|
|
|
|
NOTE: If dest is a pointer, the addition does not check if the result of
|
|
|
|
the pointer arithmetic continues to be valid (within a buffer) or not.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### inc ###
|
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
inc <dest-memory-location>
|
|
|
|
|
|
|
|
Increments the value in dest. Does not honour carry.
|
|
|
|
|
|
|
|
* It is illegal if dest is uninitialized.
|
|
|
|
* It is illegal if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 14:36:56 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n and z flags, requiring that they be in the WRITES,
|
2015-10-16 14:36:56 +00:00
|
|
|
and initializing them afterwards.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### sub ###
|
|
|
|
|
|
|
|
sub <dest-memory-location>, <src-memory-location>
|
|
|
|
|
|
|
|
Subtracts the contents of src from dest and stores the result in dest.
|
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
* It is illegal if src OR dest OR c is uninitialized.
|
|
|
|
* It is illegal if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 14:36:56 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n, z, c, and v flags, requiring that they be in the WRITES,
|
2015-10-16 14:36:56 +00:00
|
|
|
and initializing them afterwards.
|
|
|
|
|
|
|
|
dest and src continue to be initialized afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
### dec ###
|
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
dec <dest-memory-location>
|
2015-10-16 14:36:56 +00:00
|
|
|
|
|
|
|
Decrements the value in dest. Does not honour carry.
|
|
|
|
|
|
|
|
* It is illegal if dest is uninitialized.
|
|
|
|
* It is illegal if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 14:36:56 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n and z flags, requiring that they be in the WRITES,
|
2015-10-16 14:36:56 +00:00
|
|
|
and initializing them afterwards.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### cmp ###
|
|
|
|
|
|
|
|
cmp <dest-memory-location>, <src-memory-location>
|
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
Subtracts the contents of src from dest (without considering carry) but
|
|
|
|
does not store the result anywhere, only sets the resulting flags.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 14:36:56 +00:00
|
|
|
* It is illegal if src OR dest is uninitialized.
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n, z, and c flags, requiring that they be in the WRITES,
|
2015-10-16 14:36:56 +00:00
|
|
|
and initializing them afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
### and, or, xor ###
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
and <dest-memory-location>, <src-memory-location>
|
|
|
|
or <dest-memory-location>, <src-memory-location>
|
2015-10-16 17:39:38 +00:00
|
|
|
xor <dest-memory-location>, <src-memory-location>
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
Applies the given bitwise Boolean operation to src and dest and stores
|
|
|
|
the result in dest.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
* It is illegal if src OR dest OR is uninitialized.
|
|
|
|
* It is illegal if dest is read-only.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects n and z flags, requiring that they be in the WRITES of the
|
2015-10-16 17:39:38 +00:00
|
|
|
current routine, and sets them as initialized afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
dest and src continue to be initialized afterwards.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
### shl, shr ###
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
shl <dest-memory-location>
|
2015-10-16 17:39:38 +00:00
|
|
|
shr <dest-memory-location>
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
`shl` shifts the dest left one bit position. The rightmost position becomes `c`,
|
2015-10-16 08:30:24 +00:00
|
|
|
and `c` becomes the bit that was shifted off the left.
|
|
|
|
|
2015-10-16 17:39:38 +00:00
|
|
|
`shr` shifts the dest right one bit position. The leftmost position becomes `c`,
|
|
|
|
and `c` becomes the bit that was shifted off the right.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
* It is illegal if dest is a register besides `a`.
|
|
|
|
* It is illegal if dest is read-only.
|
|
|
|
* It is illegal if dest OR c is uninitialized.
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if dest does not occur in the WRITES of the current routine.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
Affects the c flag, requiring that it be in the WRITES of the
|
2015-10-16 17:39:38 +00:00
|
|
|
current routine, and it continues to be initialized afterwards.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### call ###
|
|
|
|
|
2015-10-20 08:33:30 +00:00
|
|
|
call <executable-name>
|
|
|
|
|
|
|
|
Transfers execution to the given executable, whether that is a previously-
|
|
|
|
defined routine, or a vector location which contains the address of a routine
|
2015-10-21 18:14:59 +00:00
|
|
|
which will be called indirectly. Execution will be transferred back to the
|
|
|
|
current routine, when execution of the executable is finished.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
* It is illegal if any of the memory locations listed in the called routine's
|
|
|
|
`inputs` are uninitialized immediately before the call.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
|
|
|
Just after the call,
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
* All memory locations listed in the called routine's `trashes` are considered
|
|
|
|
to now be uninitialized.
|
|
|
|
* All memory locations listed in the called routine's `outputs` are considered
|
2017-12-01 13:09:25 +00:00
|
|
|
to now be initialized.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-21 18:14:59 +00:00
|
|
|
### goto ###
|
|
|
|
|
|
|
|
goto <executable-name>
|
|
|
|
|
|
|
|
Unilaterally transfers execution to the given executable. Execution will not
|
|
|
|
be transferred back to the current routine when execution of the executable is
|
|
|
|
finished; rather, it will be transferred back to the caller of the current
|
|
|
|
routine.
|
|
|
|
|
|
|
|
If `goto` is used in a routine, it must be in tail position. That is, it
|
|
|
|
must be the final instruction in the routine.
|
|
|
|
|
|
|
|
Just before the goto,
|
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
* It is illegal if any of the memory locations in the target routine's
|
|
|
|
`inputs` list is uninitialized.
|
2015-10-21 18:14:59 +00:00
|
|
|
|
|
|
|
In addition,
|
|
|
|
|
2017-11-17 16:56:52 +00:00
|
|
|
* The target executable's WRITES must not include any locations
|
|
|
|
that are not already included in the current routine's WRITES.
|
2015-10-21 18:14:59 +00:00
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
### if ###
|
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
if <src-memory-location> {
|
|
|
|
<true-branch>
|
2015-10-16 08:30:24 +00:00
|
|
|
} else {
|
2015-10-16 18:15:01 +00:00
|
|
|
<false-branch>
|
2015-10-16 08:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
Executes the true-branch if the value in src is nonzero, otherwise executes
|
|
|
|
the false-branch. The false-branch is optional may be omitted; in this case
|
|
|
|
it is treated like an empty block.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2015-10-16 18:15:01 +00:00
|
|
|
* It is illegal if src is not z, c, n, or v.
|
|
|
|
* It is illegal if src is not initialized.
|
|
|
|
* It is illegal if any location initialized at the end of the true-branch
|
|
|
|
is not initialized at the end of the false-branch, and vice versa.
|
2015-10-16 08:30:24 +00:00
|
|
|
|
2017-11-20 14:10:43 +00:00
|
|
|
The sense of the test can be inverted with `not`.
|
|
|
|
|
2015-10-18 12:37:35 +00:00
|
|
|
### repeat ###
|
|
|
|
|
|
|
|
repeat {
|
|
|
|
<block>
|
|
|
|
} until <src-memory-location>
|
|
|
|
|
|
|
|
Executes the block repeatedly until the src (observed at the end of the
|
|
|
|
execution of the block) is non-zero. The block is always executed as least
|
|
|
|
once.
|
|
|
|
|
|
|
|
* It is illegal if any memory location is uninitialized at the exit of
|
|
|
|
the loop when that memory location is initialized at the start of
|
|
|
|
the loop.
|
|
|
|
|
|
|
|
To simulate a "while" loop, use an `if` internal to the block, like
|
|
|
|
|
|
|
|
repeat {
|
|
|
|
cmp y, 25
|
|
|
|
if z {
|
|
|
|
}
|
|
|
|
} until z
|
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
"until" is optional, but if omitted, must be replaced with "forever":
|
2015-10-18 18:41:26 +00:00
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
repeat {
|
|
|
|
cmp y, 25
|
|
|
|
if z {
|
|
|
|
}
|
|
|
|
} forever
|
2015-10-18 18:41:26 +00:00
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
The sense of the test can be inverted with `not`.
|
2015-10-18 18:41:26 +00:00
|
|
|
|
2017-11-20 13:25:09 +00:00
|
|
|
repeat {
|
|
|
|
cmp y, 25
|
|
|
|
if z {
|
|
|
|
}
|
|
|
|
} until not z
|
2015-10-18 18:41:26 +00:00
|
|
|
|
2018-03-23 17:13:46 +00:00
|
|
|
### for ###
|
|
|
|
|
|
|
|
for <dest-memory-location> (up|down) to <literal-byte> {
|
|
|
|
<block>
|
|
|
|
}
|
|
|
|
|
|
|
|
Executes the block repeatedly, incrementing or decrementing the
|
|
|
|
dest-memory-location at the end of the block, until the value of
|
|
|
|
the dest-memory-location has gone past the literal-byte.
|
|
|
|
|
|
|
|
The block is always executed as least once.
|
|
|
|
|
|
|
|
* It is illegal if any memory location is uninitialized at the exit of
|
|
|
|
the loop when that memory location is initialized at the start of
|
|
|
|
the loop.
|
|
|
|
|
2015-10-16 08:30:24 +00:00
|
|
|
Grammar
|
|
|
|
-------
|
|
|
|
|
2018-03-27 11:36:33 +00:00
|
|
|
Program ::= {ConstDefn | TypeDefn} {Defn} {Routine}.
|
|
|
|
ConstDefn::= "const" Ident<new> Const.
|
2018-02-06 11:46:11 +00:00
|
|
|
TypeDefn::= "typedef" Type Ident<new>.
|
2018-03-27 11:36:33 +00:00
|
|
|
Defn ::= Type Ident<new> [Constraints] (":" Const | "@" LitWord).
|
2018-02-12 14:53:49 +00:00
|
|
|
Type ::= TypeTerm ["table" TypeSize].
|
2018-02-06 11:46:11 +00:00
|
|
|
TypeExpr::= "byte"
|
|
|
|
| "word"
|
|
|
|
| "buffer" TypeSize
|
|
|
|
| "pointer"
|
2018-02-12 14:53:49 +00:00
|
|
|
| "vector" TypeTerm
|
2018-02-06 11:46:11 +00:00
|
|
|
| "routine" Constraints
|
2018-02-12 14:53:49 +00:00
|
|
|
| "(" Type ")"
|
2018-02-06 11:46:11 +00:00
|
|
|
.
|
|
|
|
TypeSize::= "[" LitWord "]".
|
2015-10-19 12:04:08 +00:00
|
|
|
Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs].
|
2018-02-06 11:46:11 +00:00
|
|
|
Routine ::= "define" Ident<new> Type (Block | "@" LitWord).
|
|
|
|
| "routine" Ident<new> Constraints (Block | "@" LitWord)
|
|
|
|
.
|
2015-10-16 08:30:24 +00:00
|
|
|
LocExprs::= LocExpr {"," LocExpr}.
|
2018-03-27 11:36:33 +00:00
|
|
|
LocExpr ::= Register | Flag | Const | Ident.
|
2015-10-16 08:30:24 +00:00
|
|
|
Register::= "a" | "x" | "y".
|
|
|
|
Flag ::= "c" | "z" | "n" | "v".
|
2018-03-27 11:36:33 +00:00
|
|
|
Const ::= Literal | Ident<const>.
|
2018-03-26 12:16:53 +00:00
|
|
|
Literal ::= LitByte | LitWord | LitBit.
|
2015-10-17 12:50:21 +00:00
|
|
|
LitByte ::= "0" ... "255".
|
2018-03-27 11:36:33 +00:00
|
|
|
LitWord ::= ["word"] "0" ... "65535".
|
2018-03-26 12:16:53 +00:00
|
|
|
LitBit ::= "on" | "off".
|
2015-10-16 08:30:24 +00:00
|
|
|
Block ::= "{" {Instr} "}".
|
2015-10-18 16:40:53 +00:00
|
|
|
Instr ::= "ld" LocExpr "," LocExpr ["+" LocExpr]
|
|
|
|
| "st" LocExpr "," LocExpr ["+" LocExpr]
|
2015-10-16 08:30:24 +00:00
|
|
|
| "add" LocExpr "," LocExpr
|
|
|
|
| "sub" LocExpr "," LocExpr
|
|
|
|
| "cmp" LocExpr "," LocExpr
|
|
|
|
| "and" LocExpr "," LocExpr
|
|
|
|
| "or" LocExpr "," LocExpr
|
|
|
|
| "xor" LocExpr "," LocExpr
|
|
|
|
| "shl" LocExpr
|
|
|
|
| "shr" LocExpr
|
|
|
|
| "inc" LocExpr
|
|
|
|
| "dec" LocExpr
|
2015-10-20 13:10:33 +00:00
|
|
|
| "call" Ident<routine>
|
|
|
|
| "goto" Ident<executable>
|
2018-03-26 12:16:53 +00:00
|
|
|
| "copy" LocExpr "," LocExpr ["+" LocExpr]
|
2015-10-18 12:37:35 +00:00
|
|
|
| "if" ["not"] LocExpr Block ["else" Block]
|
2015-10-18 14:32:28 +00:00
|
|
|
| "repeat" Block ("until" ["not"] LocExpr | "forever")
|
2018-03-27 11:36:33 +00:00
|
|
|
| "for" LocExpr ("up"|"down") "to" Const Block
|
2018-03-26 12:16:53 +00:00
|
|
|
| "with" "interrupts" LitBit Block
|
2015-10-18 12:37:35 +00:00
|
|
|
.
|