permacomputing

Source repository for the main permacomputing wiki site
git clone http://git.permacomputing.net/repos/permacomputing.git # read-only access
Log | Files | Refs

commit 8b6f7ad49221804ffaa621b150043d75d3fead9e
parent 0a44e126f2d8c7e09e94d78268b263a1da65cb0b
Author: neau <neau@web>
Date:   Wed, 22 Jun 2022 16:06:24 +0200

empty web commit

Diffstat:
Mp-code.mdwn | 21++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/p-code.mdwn b/p-code.mdwn @@ -1,4 +1,4 @@ -In computer programming, a p-code machine is a [[virtual machine]] designed to execute the assembly language of a hypothetical CPU. +A p-code machine is a [[virtual machine]] designed to execute the assembly language of a hypothetical CPU. [[Niklaus Wirth]] specified a simple p-code machine in the 1976 book Algorithms + Data Structures = Programs. The machine had 3 registers - a program counter p, a base register b, and a top-of-stack register t. There were 8 instructions: @@ -11,6 +11,25 @@ In computer programming, a p-code machine is a [[virtual machine]] designed to e jmp 0, a : jump to a jpc 0, a : jump conditional to a[6] +## Operations + + 0: begin {return} + t := b - 1; p := s[t + 3]; b := s[t + 2]; + end; + 1: s[t] := -s[t]; + 2: begin t := t - 1; s[t] := s[t] + s[t + 1] end; + 3: begin t := t - 1; s[t] := s[t] - s[t + 1] end; + 4: begin t := t - 1; s[t] := s[t] * s[t + 1] end; + 5: begin t := t - 1; s[t] := s[t] div s[t + 1] end; + 6: s[t] := ord(odd(s[t])); + 8: begin t := t - 1; s[t] := ord(s[t] = s[t + 1]) end; + 9: begin t := t - 1; s[t] := ord(s[t] <> s[t + 1]) end; + 10: begin t := t - 1; s[t] := ord(s[t] < s[t + 1]) end; + 11: begin t := t - 1; s[t] := ord(s[t] >= s[t + 1]) end; + 12: begin t := t - 1; s[t] := ord(s[t] > s[t + 1]) end; + 13: begin t := t - 1; s[t] := ord(s[t] <= s[t + 1]) end; + + See more: * [On Wikipedia](https://en.wikipedia.org/wiki/P-code_machine)