Symsyn Read online




  SYMSYN

  A programming language for non programmers

  by Isaac Stone

  The Symsyn software download page is

  http://qsys.us/downloadsymsyn

  Symsyn

  History

  Features

  The Language

  Examples

  Sample Routines

  List of Instructions

  Operating Commands

  Compiled listing of the Data Encryption Standard algorithm

  SYMSYN

  Symsyn is a simple syntax, back-to-basics, minimalist programming language which resembles a sort of assembly language for a Pascal Virtual Machine (PVM). Assemblers provide a one to one relationship between a mneumonic instruction and a hardware opcode. Similarly, Symsyn establishes a one to one relationship between an instruction and a Pascal procedure. The instruction set is, therefore, open ended and can grow into any operating environment.

  It is implemented by a compiler, SSL which generates version specific PVM code from a text file; and a runtime executive/emulator, SSX which processes the code. Both are written in Pascal. SSX has program (prog) monitoring and log functions. It is capable of running 99 progs concurrently. Multitasking is enhanced with several inter-program communication instructions which provide synchronization and data passing functions.

  The intended user is a novice programmer or a non programmer who doesn't have the time or interest to learn the conceptual niceties and abstract concepts of a more advanced and rigorous language, but needs to accomplish a given task. Symsyn's simplicity and potential could provide much of the functionality of Pascal without all of Pascal's discipline and could be an on ramp to learning Pascal.

  HISTORY

  A compiler and emulator were written for the PC under DOS to enable it to run multitasking software originally written for a minicomputer. The software drove legacy data communications protocols, code translation, encryption support, and transaction flow control for a real time banking application involving ATM's, teller terminals, and regional switches. This front end and a host computer were capable of controlling hundreds of devices. While Symsyn is decidedly different from that source code, major portions of that compiler and emulator were used here.

  FEATURES

  Real time multitasking operating environment running up to 99 progs concurrently.

  Program security - re-assignable version specific opcodes to inhibit reverse engineering.

  Extensible architecture designed to accommodate new instructions.

  Fast - each instruction variant is hard coded.

  Tight - average instruction size is 6 bytes.

  Interprogram communication (synchronization and data passing) instructions.

  Access to Free Pascal run time functions.

  Capable of running on any platform supported by Free Pascal.

  Bit, character, and word manipulation.

  Data Encryption Standard (DES) encryption instructions.

  Small footprint.

  Any algorithm can be reduced to an instruction.

  THE LANGUAGE

  As much as possible examples will be used to explain the syntax. But first, some basic principles.

  A prog consists of one or more instructions.

  One instruction or data declaration per line.

  All data declarations precede instructions.

  Labels start in column one.

  Data and instructions are free form after column one.

  Data items may be declared or just used in instructions.

  Instructions consist of a command (opcode) followed by zero or more operands.

  If the first item after the optional label is not a valid command, MOVE is assumed.

  Items are separated by one or more spaces.

  An item is indexed by attaching '.' index word to the end of the item.

  Bits are specified by attaching ':' bit number ':' bit count to the end of the word.

  Action flows from left to right, rightmost item usually receives result.

  Arithmetic is 64 bit.

  Text after '|' on a line is comment.

  There are three data types.

  Word - a 64 bit binary object residing in the program space which can be an integer or a descriptor. It can be declared as a data item or just used in an instruction. Word is the default type. Bits can be addressed by number. They are numbered 63 to 0, left to right (msb to lsb). Word array index begins at 0.

  Character String - an unstructured list of one or more characters residing in the program space. It can be declared as a data item or just used in an instruction as a literal string. Index begins at 0.

  Ansi String - a structured list of characters of any length residing outside the program space. It is never declared. All Ansi String identifiers begin with a '$'. Index begins at 1.

  The prefix '#' means size of.

  The prefix '@' means address of.

  EXAMPLES

  In the following examples, identifiers starting with

  C, D, E, are character strings

  X, Y, Z, are words

  I, J, K, are index words

  N is a count word (number of characters)

  $R, $S, $T, are ansi strings

  C : 'This is a character string'

  D : 40 ' ' | a character string of 40 spaces

  C2 : X'ABCD1234567890' | a string of hexadecimal digits

  X : 3 1000 | three word array with a value of 1000

  X1 : 0XABCDEF | a word with a hexadecimal value of ABCDEF

  X2 : 0b100101 | a word with a binary value of 100101

  Y : @C | a word with a value equal to the address of C

  Y1 : #C | a word with a value equal to the size of C

  CEQ = X | CEQ will use the address of X but be treated as a

  | character

  X | set X to zero

  + X | increment X by 1

  + 0XA9822B Y | add hex value to Y

  X Y | move X to Y

  X:3:4 Y | move 4 bits starting with bit number 3 to Y

  C $S | move the character string C to the ansi string $S

  $S C #C | move (size of C) characters from ansi string $S to C

  C D N | move N characters from C to D

  + 'ABC' $S | add character string 'ABC' to the end of ansi string $S

  #$S X | move the size of string $S to X

  find 'A' $R Z | find the position of 'A' in string $R, store in Z

  wait 'EV' $T | wait for the event 'EV' to be posted and store data in $T

  'hello world' [] | display 'hello world' on the console (stdout)

  maketext 'tfile1' tfh | create a text file named 'tfile1' , tfh will be the file handle

  'hello world' [tfh] | move (write) 'hello world' to the text file

  close tfh | close file

  X.I Z | move the Ith word in array X to Z

  datetime $R | set string $R to system date and time

  buildabuick X Y | not yet implemented

  SAMPLE ROUTINES

  * * *

  | the following if clause

  if i LT 1000

  + 5 x

  .

  .

  .

  endif

  | becomes a 'while' clause with the addition of a 'goif' instruction

  if i LT 1000

  + 5 x

  .

  .

  .

  goif

  endif

  | and becomes an iterative 'for' loop with the addition of an index variable

  i

  if i LT 1000

  + 5 x

  .

  .

  .

  + i

  goif

  endif

  * * *

  | the following prog (T1) will cause 99 progs to run

  symsyn 'R T1' | co
mmand to Symsyn to run T1

  lp

  delay 100 | sleep for 100 milliseconds

  go lp

  * * *

  | the following prog will time a loop and display the result on the console

  datetime strt | system date and time to strt

  I

  if I LT 100000000

  + I

  goif

  endif

  datetime stopp | system date and time to stopp

  msbetween strt stopp rslt | milliseconds between strt and stopp

  ~ rslt $s | convert binary to decimal string

  $s [] | display result

  * * *

  | the following prog reads a text file and displays it on the console

  opentext 'sorttext.txt' fid

  if ioresult eq 0 | ioresult = -1 at end of file

  [fid] $s | move a record from the file to the string

  $s [] | display string on the console

  goif

  endif

  * * *

  | the square root of the sum of the squares

  x : 2 0 | array (vector) x ( 2 members each a value of 0 )

  3 x.0 | first member = 3

  4 x.1 | second member = 4

  vmul x x x | multiply each member of array x by same in x, store in x

  vsum x y | add all the members of array x place total in word y

  sqrt y z | square root of y in z (rounded) = 5

  * * *

  | a very simplified, shortened version of 99 bottles

  if 99 GT 1 | numbers are variables initialized to value

  ~ 99 $S | convert to string

  + ' Bottles of beer on the wall ' $S | concatenate string

  + $S $S | add it to itself

  #$S I | length to I

  - 12 I | decrement I

  I #$S | set length to shortened value

  $S [] | output string

  - 99 | decrement variable 99 (a VERY bad practice)

  'Take one down and pass it around' [] | output string

  goif | re-test

  endif

  * * *

  | DES encryption using the edes instruction

  key : x'0e329232ea6d0d73'

  data : x'8787878787878787'

  edes key data | encrypt data with key

  data $s | move data to string

  unpackhex $s $s | unpack

  $s [] | output result - 0000000000000000

  * * *

  | Trabb Pardo–Knuth algorithm

  a : 11 0

  i

  if i LE 10

  [] $s

  ~ $s w

  w a.i

  + i

  goif

  endif

  10 i

  if i GE 0

  call f

  if x GT 400

  'too large' $s

  else

  ~ x $s

  endif

  ~ i $r

  + ' ' $r

  + $r $s.1

  $s []

  - i

  goif

  endif

  stop

  f a.i t

  * t t x

  * x t x

  * 5 x

  abs t

  sqrt t y

  + y x

  return

  * * *

  INSTRUCTIONS

  + C $S | add character string to end of ansi string

  + C $S N | as above for N characters

  + C $S.I N | insert string into string at I for N

  + X | add 1 to X

  + X Y | add X to Y

  + X Y Z | add X to Y store in Z

  + $S $R | add $S to end of $R

  + $S $R.I | insert $S to $R at I

  ABS X | make X a positive number

  AND X Y | logical and X to Y

  AND X Y Z | as above store in Z

  CALL LABEL | subroutine call

  CALLTHRU X | call address in X

  CLOSE X | close file

  ~ X $S | convert binary to decimal string

  ~ $S X | convert decimal string to binary

  DATETIME X | system date and time to binary

  DATETIME $S | system date and time to string

  DDES KEY DATA | decrypt data (8 bytes) with key (8 bytes) result in data

  DELAY N | sleep for N milliseconds

  / X Y Z | divide X by Y store in Z

  ENDIF | end of the IF clause

  EDES KEY DATA | encrypt data (8 bytes) with key (8 bytes) result in data

  ELSE | code follows that will be run if the previous IF was not true

  FILL 'A' C | fill string C with 'A'

  FILL 123 X | fill array X with value 123

  FIND C $S I | find character C in string store address in I

  FIND $S $R I | find string in string store address in I

  GOIF | go back to previous IF and retest

  GO LABEL | go to label

  GOTHRU X | go to address in X

  GRAB C | own resource named in string C

  IF X BIT 23 | if bit number 23 of X is a 1

  IF C EQ D | if character equals character

  IF X EQ Y | if integer equals integer

  IF $S EQ $R | if string equals string

  IF C GE D | greater than or equal to

  IF X GE Y |

  IF $S GE $R |

  IF C GT D | greater than

  IF X GT Y |

  IF $S GT $R |

  IF C LE D | less than or equal to

  IF X LE Y |

  IF $S LE $R |

  IF C LT D | less than

  IF X LT Y |

  IF $S LT $R |

  IF C NE D | not equal

  IF X NE Y |

  IF $S NE $R |

  IFPOSTED C | if event C has been posted

  IFPOSTED C $S | if event C has been posted, receive data into $S

  IORESULT | value of the last I/O operation

  MAKEFILE C X | create an untyped file named by string C. X will be the handle

  MAKEFILE $S X | as above with string $S

  MAKETEXT C X | create a text file named by string C

  MAKETEXT $S X | as above

  C D | move character(s) C to D

  C D N | move N characters from C to D

  C $S | move character(s) C to string $S

  C $S N | move N characters from C to $S

  C $S.I N | as above to location I in $S

  C [] | display string C

  C.I D.J N | move N characters from C at I to D at J

  X | move 0 to X

  X Y | move X to Y

  X Y.I | move X to word I in array Y

  X $S.I | move 8 bytes from word X to string $S at location I

  X #$S | set string length of $S to value in X

  X.I Y | move word I in array X to Y

  X.I Y.J | move word I in array X to word J in array Y

  X:18:4 Y | move the 4 bits of X starting with bit number 18 to Y

  Y X:18:4 | move least significant 4 bits of Y to X starting at bit number 18

  $S | set length of string $S to 0

  $S C | move string $S to C

  $S C N | move N characters from $S to C

  $S $R | move $S to $R

  $S $R N | move N characters from $S to $R

  $S X | move 8 bytes from $S to word X

  $S.I C N | move N characters from location I in string $S to C

  $S.I C.J N | move N characters from location I in $S to J in $R

  $S.I X | move 8 bytes from location I in $S to X

  $S.I $R N | move N characters from I in $S to $R

  [] $S | read from console message to this prog, place in $S

  #$S X | move length of $S to X

  LOWERCASE $S | make characters in string lower case

  MAX X Y Z | move the larger of X and Y to Z

  MIN X Y Z | move the smaller of X and Y to Z

  MSBETWEEN X Y Z | milliseconds between X and Y into Z

  * X Y | multiply X times Y, result in Y

  * X Y Z | multiply X times Y result in Z

  ^ X Y Z | raise X to the Y po
wer store in Z

  NOT X | logical not of X

  OPENFILE C X | open an existing untyped file named by string C. X will be the handle

  OPENFILE $S X | as above with string $S

  OPENTEXT C X | open an exiting text file

  OPENTEXT $S X | as above

  OR X Y | logical or X with Y result in Y

  OR X Y Z | logical or X with Y result in Z

  PACKHEX $R $S | compact displayable hex characters to 4 bit nibbles