lg archive
lg lgpio C lgpio Python Daemon rgpio C rgpio Python rgs Download Examples FAQ Site Map

Scripts

Scripts

Scripts are programs to be stored and executed by the rgpiod daemon. They are intended to mitigate any performance problems associated with the daemon server/client model.

Scripts are work in progress.

Virtual machine

A script runs within a virtual machine with

a 32 bit accumulator A.
a flags register F.
a program counter PC.

Each script has

10 parameters named 0 through 9.
150 variables named 0 through 149.
50 labels which are named by any unique number.

Commands

Many lg commands may be used within a script. However some commands do not work within the script model as designed and are not permitted.

The following commands are not permitted within a script:


File - FL FO FR FW

I2C - I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ

Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU

Serial - SERO SERR SERW SLR

SPI - SPIR SPIW SPIX

The following commands are only permitted within a script:


CommandDescriptionDefinition
ADD xAdd x to accumulatorA+=x; F=A
AND xAnd x with accumulatorA&=x; F=A
CALL LCall subroutine at tag Lpush(PC+1); PC=L
CMP xCompare x with accumulatorF=A-x
DCR yDecrement register--*y; F=*y
DCRADecrement accumulator--A; F=A
DIV xDivide x into accumulatorA/=x; F=A
HALTHaltHalt
INR yIncrement register++*y; F=*y
INRAIncrement accumulator++A; F=A
JGE LJump if >= 0 to tag Lif (F>=0) PC=L
JGT LJump if > 0 to tag Lif (F>0) PC=L
JLE LJump if <= 0 to tag Lif (F<=0) PC=L
JLT LJump if < 0 to tag Lif (F<0) PC=L
JMP LJump to tag LPC=L
JNZ LJump if non-zero to tag Lif (F) PC=L
JZ LJump if zero to tag Lif (!F) PC=L
LD y xLoad register with x*y=x
LDA xLoad accumulator with xA=x
MLT xMultiply x with accumulatorA*=x; F=A
MOD xModulus x with accumulatorA%=x; F=A
OR xOr x with accumulatorA|=x; F=A
POP yPop registery=pop()
POPAPop accumulatorA=pop()
PUSH yPush registerpush(y)
PUSHAPush accumulatorpush(A)
RETReturn from subroutinePC=pop()
RL y xRotate left register x bits*y<<=x; F=*y
RLA xRotate left accumulator x bitsA<<=x; F=A
RR y xRotate right register x bits*y>>=x; F=*y
RRA xRotate right accumulator x bitsA>>=x; F=A
SHL y xShift left register x bits*y<<=x; F=*y
SHLA xShift left accumulator x bitsA<<=x; F=A
SHR y xShift right register x bits*y>>=x; F=*y
SHRA xShift right accumulator x bitsA>>=x; F=A
STA yStore accumulator in registery=A
SUB xSubtract x from accumulatorA-=x; F=A
SYS strRun external scriptsystem(str); F=A
TAG LLabel the current positionN/A
X y1 y2Exchange registers y1 and y2t=*y1;*y1=*y2;*y2=t
XA yExchange accumulator and registert=A;A=*y;*y=t
XOR xXor x with accumulatorA^=x; F=A


x may be a constant, a parameter (p0-p9), or a variable (v0-v149).

y may be a parameter (p0-p9), or a variable (v0-v149). If p or v isn't specified y is assumed to be a variable.

The SYS script receives two unsigned parameters: the accumulator A and the current GPIO levels.

[lg] [lgpio C] [lgpio Python] [Daemon] [rgpio C] [rgpio Python] [rgs] [Download] [Examples] [FAQ] [Site Map]
© 2020-2021
(2021-01-16 21:12)