next up previous
Next: Control-Related Instructions Up: Primitive Instructions Previous: Primitive Instructions


Basic Data Stack-Related Instructions

  1. ARITHMETIC. c0(),c1(), c2(), ..., c5() return constants 0, 1, 2, 3, 4, 5, respectively; inc(x) returns $x+1$; dec(x) returns $x-1$; by2(x) returns $2x$; add(x,y) returns $x+y$; sub(x,y) returns $x-y$; mul(x,y) returns $x*y$; div(x,y) returns the smallest integer $\leq x/y$; powr(x,y) returns $x^y$ (and costs $y$ unit time steps).

  2. BOOLEAN. Operand eq(x,y) returns 1 if $x=y$, otherwise 0. Analogously for geq(x,y) (greater or equal), grt(x,y) (greater). Operand and(x,y) returns 1 if $x>0$ and $y>0$, otherwise 0. Analogously for or(x,y). Operand not(x) returns 1 if $x \leq 0$, otherwise 0.

  3. SIMPLE STACK MANIPULATORS. del() decrements dp; clear() sets $dp :=0$; dp2ds() returns dp; setdp(x) sets $dp :=x$; ip2ds() returns $cs[cp].ip$; base() returns $cs[cp].base$; fromD() returns $Ds[Dp]$; toD() pushes $ds[dp]$ onto Ds; delD() decrements Dp; topf() returns the integer name of the most recent self-made function; intopf() and outopf() return its number of requested inputs and outputs, respectively; popf() decrements fnp, returning its old value; xmn(m,n) exchanges the $m$-th and the $n$-th elements of ds, measured from the stack's top; ex() works like xmn(1,2); xmnb(m,n) exchanges the $m$-th and the $n$-th elements above the current base $ds[cs[cp].base]$; outn(n) returns $ds[dp-n+1]$; outb(n) returns $ds[cs[cp].base + n]$ (the $n$-th element above the base pointer); inn(n) copies $ds[dp]$ onto $ds[dp-n+1]$; innb(n) copies $ds[dp]$ onto $ds[cs[cp].base + n]$.

  4. PUSHING CODE. Instruction getq(n) pushes onto ds the sequence beginning at the start address of the $n$-th frozen program (either user-defined or frozen by OOPS) and ending with the program's final token. insq(n,a) inserts the $n$-th frozen program above $ds[cs[cp].base+a]$, then increases dp by the program size. Useful for copying previously frozen code into modifiable memory, to later edit the copy.

  5. EDITING STRINGS ON STACK. Instruction cpn(n) copies the n topmost ds entries onto the top of ds, increasing dp by $n$; up() works like cpn(1); cpnb(n) copies $n$ ds entries above $ds[cs[cp].base]$ onto the top of ds, increasing dp by $n$; mvn(a,b,n) copies the $n$ ds entries starting with $ds[cs[cp].base+a]$ to $ds[cs[cp].base+b]$ and following cells, appropriately increasing dp if necessary; ins(a,b,n) inserts the $n$ ds entries above $ds[cs[cp].base+a]$ after $ds[cs[cp].base+b]$, appropriately increasing dp; deln(a,n) deletes the $n$ ds entries above $ds[cs[cp].base+a]$, appropriately decreasing dp; find(x) returns the stack index of the topmost entry in ds matching $x$; findb(x) the index of the first ds entry above base $ds[cs[cp].base]$ matching $x$. Many of the above instructions can be used to edit stack contents that may later be interpreted as executable code.


next up previous
Next: Control-Related Instructions Up: Primitive Instructions Previous: Primitive Instructions
Juergen Schmidhuber 2004-04-15

Back to OOPS main page