program interp(input,output,CodeFile); {$BOX This program is an interpreter for the P-code produced by COMP. $EBOX} {$BOX The instructions used are very close to the P-code used in the pascal compiler. Extensions have been made where convenient. The stack notation shows the stack before and after the operation. ( --- ) would mean that is on top of the stack and is immediately beneath it before the operation and the sum of x and y is left afterwards. The notation [x] means the memory location addressed by x. The type suffixes are these : A -- address B -- boolean C -- character I -- integer O -- cardinal (ordinal) R -- real S -- bitset Z -- string result instruction type action ---------------- --------- ---------------------------------- LDCI Q integer ( --- ) LDCO Q cardinal ( --- ) LDCB Q boolean ( --- ) LDCC Q char ( --- ) LDCR Q real ( --- ) LDCS Q bitset ( --- ) LDCA Q address ( ---
) LODI P Q integer ( --- ) LODO P Q cardinal ( --- ) LODR P Q real ( --- ) LODB P Q boolean ( --- ) LODC P Q char ( --- ) LODS P Q bitset ( --- ) STRI P Q integer ( --- ) STRO P Q cardinal ( --- ) STRR P Q real ( --- ) STRB P Q boolean ( --- ) STRC P Q char ( --- ) STRS P Q bitset ( --- ) LDA P Q pointer ( ---
) LCA string ( ---
) INDI Q integer (
--- ) INDO Q cardinal (
--- ) INDR Q real (
--- ) INDC Q char (
--- ) INDS Q bitset (
--- ) INDA Q pointer (
--- ) STOI integer ( --- ) STOO cardinal ( --- ) STOR real ( --- ) STOB boolean ( --- ) STOC char ( --- ) STOS bitset ( --- ) MOV Q block copy ( --- ) MPI integer ( --- ) MPC cardinal ( --- ) MPR real ( --- ) DVI integer ( --- ) DVC cardinal ( --- ) DVR real ( --- ) ADI integer ( --- ) ADC cardinal ( --- ) ADR real ( --- ) SBI integer ( --- ) SBC cardinal ( --- ) SBR real ( --- ) IXA Q pointer ( --- ) GEQx x ( --- ) EQUx x ( --- ) LEQx x ( --- ) LESx x ( --- ) MODI integer ( --- ) MODC cardinal ( --- ) NGI integer ( --- < -int > ) NGR real ( --- < -real > ) INCI Q integer ( --- ) INCO Q cardinal ( --- --- ) INCA Q pointer (
--- ) DECI Q integer ( --- ) DECO Q cardinal ( --- --- ) DECA Q pointer (
--- ) CHKI P Q ---- ( --- ) (unchanged) CHKO P Q ---- ( --- ) (unchanged) CHKC P Q ---- ( --- ) (unchanged) CHKA P Q ---- ( --- ) (unchanged) TSTI P Q