Short tour of PAL
Contents
Short tour of PAL in release 0.6.x
In release 0.6.x, only the PROSE Assembly Language (PAL) is available, and then only a subset of those instructions. So be aware, it's very low-level programming at this time. To learn more about the PROSE Programming Language, visit http://prose.sourceforge.net.
It is suggested you begin with the following articles before attempting this tour.
This article gives a brief tour of the following features in the PROSE Assembly Language.
Registers and indices
There are 93 unique instruction codes (opcodes) in PAL, 15 registers, 8 special register keywords and 5 data entry macros. Run prism -l
and you'll see a list of them all:
$ prism -l ------------------------------------------------------------ INSTRUCTIONS 0x80 noop 0x81 stack/push 0x82 stack/pull 0x83 stack/peek 0x84 stack/lock 0x85 stack/unlock 0x86 stack/flush 0x89 obj/def 0x8a obj/clone 0x8b obj/edit 0x8c obj/commit 0x8d obj/del 0x8e obj/addr 0x8f obj/pa 0x90 obj/child 0x91 obj/dump 0x92 class/add 0x93 class/del 0x94 class/load 0x95 class/load() 0x96 class/test 0x97 attr/add 0x98 attr/del 0x99 attr/mod 0x9a attr/mvadd 0x9b attr/mvdel 0x9c attr/mvmod 0x9d attr/load 0x9e attr/load() 0x9f attr/test 0xa0 attr/mvtest 0xa1 attr/copy 0xa2 attr/copy() 0xa3 attr/direct 0xa6 op/incr 0xa7 op/decr 0xa8 op/add 0xa9 op/sub 0xaa op/mult 0xab op/div 0xac op/mod 0xad op/not 0xae op/and 0xaf op/or 0xb0 op/xor 0xb1 op/shl 0xb2 op/shr 0xb3 op/mask 0xb4 op/swap 0xbc error/def 0xbd error/now 0xbe error/jmp 0xbf error/clr 0xc0 func/def 0xc1 func/call 0xc2 func/bcall 0xc3 func/rtn 0xc4 local/jmp() 0xc5 local/jsr() 0xc6 local/jmp 0xc7 local/jsr 0xc8 local/rtn 0xc9 reg/move 0xca reg/load 0xcb reg/jmpeq 0xcc reg/jmpneq 0xcd reg/jsreq 0xce reg/jsrneq 0xcf reg/dump 0xd0 reg/load() 0xd1 reg/clr 0xd2 reg/index 0xd3 reg/cmp 0xd4 reg/save() 0xd5 reg/copy 0xd6 reg/copy() 0xd7 reg/conv 0xd8 reg/lcmp 0xd9 reg/rcmp 0xda reg/scan 0xe8 opa/add 0xe9 opa/sub 0xea opa/mult 0xeb opa/div 0xec opa/mod 0xed opa/not 0xee opa/and 0xef opa/or 0xf0 opa/xor 0xf1 opa/shl 0xf2 opa/shr 0xfb debug/source 0xfc debug/level ------------------------------------------------------------ INDICES (with Accumulator) 0x60 to 0x63 A, LABEL 0x64 to 0x67 A, DLABEL 0x68 to 0x6b A, OBJREF 0x6c to 0x6f A, TEXT 0x70 to 0x73 A, RAW 0x7c ------- A, PTRPOS 0x7d ------- A, PTRNEG ------------------------------------------------------------ INDICES (without Accumulator) 0x40 to 0x43 LABEL 0x44 to 0x47 DLABEL 0x48 to 0x4b OBJREF 0x4c to 0x4f TEXT 0x50 to 0x53 RAW 0x5c ------- PTRPOS 0x5d ------- PTRNEG ------------------------------------------------------------ REGISTERS (with Accumulator) 0x20 A, P0 0x21 A, P1 0x22 A, P2 0x23 A, P3 0x24 A, P4 0x25 A, P5 0x26 A, P6 0x27 A, P7 0x28 A, P8 0x29 A, P9 0x2a A, P10 0x2b A, P11 0x2c A, P12 0x2d A, P13 0x37 A, A 0x38 A, SFLG 0x39 A, SCMP 0x3a A, LOCK 0x3b A, PCTX 0x3c A, PEEK 0x3d A, PULL 0x3e A, PUSH 0x3f A, NULL ------------------------------------------------------------ REGISTERS (without Accumulator) 0x00 P0 0x01 P1 0x02 P2 0x03 P3 0x04 P4 0x05 P5 0x06 P6 0x07 P7 0x08 P8 0x09 P9 0x0a P10 0x0b P11 0x0c P12 0x0d P13 0x17 A 0x18 SFLG 0x19 SCMP 0x1a LOCK 0x1b PCTX 0x1c PEEK 0x1d PULL 0x1e PUSH 0x1f NULL ------------------------------------------------------------ MACROS 0x20 EQUB 0x40 EQUW 0x60 EQUD 0x80 EQUS 0xa0 EQUP
Registers are pointers to units of data. They can point to text strings, nodes (objects in the nexus), program code, and a variety of other data types. The type of data is always associated with the register, so that bytecode instructions can validate, to a certain degree, that the arguments they have been given are correct.
Besides registers, other valid arguments that may be passed to PAL instructions are called indices. An index parameter is so called because when it is compiled into bytecode, it is saved to a table, and the argument itself converted to a numeric index. There are 7 types of index, although only 5 of these can be used explicitly within a PAL source file. Indices allow for data such as arbitrary text, code references and object references to be input.
The following code example demonstrates the use of registers and indices. It loads text and code pointers into a number of registers, and then dumps the contents to the screen.
% This program will only have a ._init section for now ._init % Load registers P0 and P1 reg/load P0, [A violin concerto], P1, [Brahms] reg/load P10, &[._init], P11, [Brahms] % Report contents of registers reg/dump P0, P1, P10, P11 obj/dump P0, P1, P10, P11
Compile and run the code:
$ prism test $ prose test register: P0 type: PSUNIT_TYPE_PALTEXT 0x2b82b788504b (len 0x000011) register: P1 type: PSUNIT_TYPE_PALTEXT 0x2b82b788505e (len 0x000006) register: P10 type: PSUNIT_TYPE_PALCODE 0x0000 register: P11 type: PSUNIT_TYPE_PALTEXT 0x2b82b788505e (len 0x000006) 0x2b82b788504b (len 0x000011) A violin concerto 0x2b82b788505e (len 0x000006) Brahms 0x2b82b788505e (len 0x000006) Brahms prose: ERROR: no main() function found, nothing to do
The error 'no main() function found' means that the PROSE engine could only call _init
sections and there was no main
function from which to begin full program execution. For the purposes of this exercise the error can be ignored. For simplicity we have omitted defining a main
function (as functions are described later on in this tour).
If you run prism -v
on the binary, you'll see that the text 'A violin concerto' and 'Brahms' were given the index numbers 0 and 1 respectively. Note that even though the text 'Brahms' appeared twice in the source file, it only has one entry in the text table.
$ prism -v test ------------------------------------------------------------ PROSE HEADER File: test.pro Size: 112 bytes Compiled by: prism Compiler version code: 0.6.0 Compile date: Wed Sep 30 11:51:25 2009 ------------------------------------------------------------ INSTRUCTION CODE 000000 : ca 00 4c 00 01 4c 01 ca 0a 5d 09 0b 4c 01 cf 00 000010 : 01 0a 0b 91 00 01 0a 0b Size: 24 bytes ------------------------------------------------------------ CODE LABELS idx 000000 len 000005 [_init] Size: 7 bytes ------------------------------------------------------------ CODE ADDRESSES idx 000000 ref 000000 Size: 1 bytes ------------------------------------------------------------ TEXT DATA idx 000000 len 000011 [A violin concerto] idx 000001 len 000006 [Brahms] Size: 27 bytes ------------------------------------------------------------ DATA LABELS Size: 0 bytes ------------------------------------------------------------ DATA XREF TABLE Size: 0 bytes ------------------------------------------------------------ DATA SEGMENTS Size: 0 bytes ------------------------------------------------------------ END OF FILE