<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
a	O
p-code	O
machine	O
(	O
portable	O
code	O
machine	O
)	O
is	O
a	O
virtual	B-Architecture
machine	I-Architecture
designed	O
to	O
execute	O
p-code	O
(	O
the	O
assembly	B-Language
language	I-Language
or	O
machine	B-Language
code	I-Language
of	O
a	O
hypothetical	O
central	B-General_Concept
processing	I-General_Concept
unit	I-General_Concept
(	O
CPU	O
)	O
)	O
.	O
</s>
<s>
This	O
term	O
is	O
applied	O
both	O
generically	O
to	O
all	O
such	O
machines	O
(	O
such	O
as	O
the	O
Java	B-Language
virtual	I-Language
machine	I-Language
(	O
JVM	B-Language
)	O
and	O
MATLAB	B-Language
precompiled	O
code	O
)	O
,	O
and	O
to	O
specific	O
implementations	O
,	O
the	O
most	O
famous	O
being	O
the	O
p-Machine	O
of	O
the	O
Pascal-P	O
system	O
,	O
particularly	O
the	O
UCSD	B-Language
Pascal	I-Language
implementation	O
,	O
among	O
whose	O
developers	O
,	O
the	O
p	O
in	O
p-code	O
was	O
construed	O
to	O
mean	O
pseudo	O
more	O
often	O
than	O
portable	O
,	O
thus	O
pseudo-code	O
meaning	O
instructions	O
for	O
a	O
pseudo-machine	O
.	O
</s>
<s>
Although	O
the	O
concept	O
was	O
first	O
implemented	O
circa	O
1966	O
—	O
as	O
O-code	B-Language
for	O
the	O
Basic	B-Language
Combined	I-Language
Programming	I-Language
Language	I-Language
(	O
BCPL	B-Language
)	O
and	O
P	O
code	O
for	O
the	O
language	O
Euler	B-Language
—	O
the	O
term	O
p-code	O
first	O
appeared	O
in	O
the	O
early	O
1970s	O
.	O
</s>
<s>
Two	O
early	O
compilers	B-Language
generating	O
p-code	O
were	O
the	O
Pascal-P	O
compiler	B-Language
in	O
1973	O
,	O
by	O
Kesav	O
V	O
.	O
Nori	O
,	O
Urs	O
Ammann	O
,	O
Kathleen	O
Jensen	O
,	O
Hans-Heinrich	O
Nägeli	O
,	O
and	O
Christian	O
Jacobi	O
,	O
and	O
the	O
Pascal-S	O
compiler	B-Language
in	O
1975	O
,	O
by	O
Niklaus	O
Wirth	O
.	O
</s>
<s>
Programs	O
that	O
have	O
been	O
translated	O
to	O
p-code	O
can	O
either	O
be	O
interpreted	B-Application
by	O
a	O
software	O
program	O
that	O
emulates	O
the	O
behavior	O
of	O
the	O
hypothetical	O
CPU	O
,	O
or	O
translated	O
into	O
the	O
machine	B-Language
code	I-Language
of	O
the	O
CPU	O
on	O
which	O
the	O
program	O
is	O
to	O
run	O
and	O
then	O
executed	O
.	O
</s>
<s>
If	O
there	O
is	O
sufficient	O
commercial	O
interest	O
,	O
a	O
hardware	O
implementation	O
of	O
the	O
CPU	O
specification	O
may	O
be	O
built	O
(	O
e.g.	O
,	O
the	O
Pascal	B-Device
MicroEngine	I-Device
or	O
a	O
version	O
of	O
a	O
Java	B-Language
processor	I-Language
)	O
.	O
</s>
<s>
Compared	O
to	O
direct	O
translation	O
into	O
native	O
machine	B-Language
code	I-Language
,	O
a	O
two-stage	O
approach	O
involving	O
translation	O
into	O
p-code	O
and	O
execution	O
by	O
interpreting	B-Application
or	O
just-in-time	O
compilation	B-Language
(	O
JIT	O
)	O
offers	O
several	O
advantages	O
.	O
</s>
<s>
It	O
is	O
much	O
easier	O
to	O
write	O
a	O
small	O
p-code	O
interpreter	O
for	O
a	O
new	O
machine	O
than	O
it	O
is	O
to	O
modify	O
a	O
compiler	B-Language
to	O
generate	O
native	B-Language
code	I-Language
for	O
the	O
same	O
machine	O
.	O
</s>
<s>
Generating	O
machine	B-Language
code	I-Language
is	O
one	O
of	O
the	O
more	O
complicated	O
parts	O
of	O
writing	O
a	O
compiler	B-Language
.	O
</s>
<s>
This	O
makes	O
it	O
useful	O
for	O
getting	O
a	O
compiler	B-Language
up	O
and	O
running	O
quickly	O
.	O
</s>
<s>
Since	O
p-code	O
is	O
based	O
on	O
an	O
ideal	O
virtual	B-Architecture
machine	I-Architecture
,	O
a	O
p-code	O
program	O
is	O
often	O
much	O
smaller	O
than	O
the	O
same	O
program	O
translated	O
to	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
When	O
the	O
p-code	O
is	O
interpreted	B-Application
,	O
the	O
interpreter	B-Application
can	O
apply	O
additional	O
run-time	O
checks	O
that	O
are	O
difficult	O
to	O
implement	O
with	O
native	B-Language
code	I-Language
.	O
</s>
<s>
One	O
of	O
the	O
significant	O
disadvantages	O
of	O
p-code	O
is	O
execution	O
speed	O
,	O
which	O
can	O
sometimes	O
be	O
remedied	O
via	O
JIT	O
compiling	B-Language
.	O
</s>
<s>
P-code	O
is	O
often	O
also	O
easier	O
to	O
reverse-engineer	O
than	O
native	B-Language
code	I-Language
.	O
</s>
<s>
In	O
the	O
early	O
1980s	O
,	O
at	O
least	O
two	O
operating	B-General_Concept
systems	I-General_Concept
achieved	O
machine	B-Operating_System
independence	I-Operating_System
through	O
extensive	O
use	O
of	O
p-code	O
.	O
</s>
<s>
The	O
Business	B-Application
Operating	I-Application
System	I-Application
(	O
BOS	O
)	O
was	O
a	O
cross-platform	B-Operating_System
operating	B-General_Concept
system	I-General_Concept
designed	O
to	O
run	O
p-code	O
programs	O
exclusively	O
.	O
</s>
<s>
The	O
UCSD	B-Language
p-System	I-Language
,	O
developed	O
at	O
The	O
University	O
of	O
California	O
,	O
San	O
Diego	O
,	O
was	O
a	O
self-compiling	O
and	O
self-hosting	O
operating	B-General_Concept
system	I-General_Concept
based	O
on	O
p-code	O
optimized	O
for	O
generation	O
by	O
the	O
Pascal	B-Application
language	I-Application
.	O
</s>
<s>
In	O
the	O
1990s	O
,	O
translation	O
into	O
p-code	O
became	O
a	O
popular	O
strategy	O
for	O
implementations	O
of	O
languages	O
such	O
as	O
Python	B-Language
,	O
Microsoft	B-Application
P-Code	I-Application
in	O
Visual	B-Language
Basic	I-Language
,	O
and	O
Java	B-Language
bytecode	I-Language
in	O
Java	B-Language
.	O
</s>
<s>
The	O
language	O
Go	B-Application
uses	O
a	O
generic	O
,	O
portable	O
assembly	O
as	O
a	O
form	O
of	O
p-code	O
,	O
implemented	O
by	O
Ken	O
Thompson	O
as	O
an	O
extension	O
of	O
the	O
work	O
on	O
Plan	B-Operating_System
9	I-Operating_System
from	I-Operating_System
Bell	I-Operating_System
Labs	I-Operating_System
.	O
</s>
<s>
Unlike	O
Common	O
Language	O
Runtime	O
(	O
CLR	O
)	O
bytecode	O
or	O
JVM	B-Language
bytecode	I-Language
,	O
there	O
is	O
no	O
stable	O
specification	O
,	O
and	O
the	O
Go	B-Application
build	O
tools	O
do	O
not	O
emit	O
a	O
bytecode	O
format	O
to	O
be	O
used	O
at	O
a	O
later	O
time	O
.	O
</s>
<s>
The	O
Go	B-Application
assembler	B-Language
uses	O
the	O
generic	O
assembly	B-Language
language	I-Language
as	O
an	O
intermediate	B-Application
representation	I-Application
,	O
and	O
Go	B-Application
executables	B-Application
are	O
machine-specific	O
statically	B-General_Concept
linked	I-General_Concept
binaries	O
.	O
</s>
<s>
Like	O
many	O
other	O
p-code	O
machines	O
,	O
the	O
UCSD	O
p-Machine	O
is	O
a	O
stack	B-Application
machine	I-Application
,	O
which	O
means	O
that	O
most	O
instructions	O
take	O
their	O
operands	O
from	O
a	O
stack	B-Application
,	O
and	O
place	O
results	O
back	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
Thus	O
,	O
the	O
add	O
instruction	O
replaces	O
the	O
two	O
topmost	O
elements	O
of	O
the	O
stack	B-Application
with	O
their	O
sum	O
.	O
</s>
<s>
Like	O
Pascal	B-Application
,	O
the	O
p-code	O
is	O
strongly	O
typed	O
,	O
supporting	O
boolean	O
(	O
b	O
)	O
,	O
character	O
(	O
c	O
)	O
,	O
integer	O
(	O
i	O
)	O
,	O
real	O
(	O
r	O
)	O
,	O
set	O
(	O
s	O
)	O
,	O
and	O
pointer	O
(	O
a	O
)	O
data	O
types	O
natively	O
.	O
</s>
<s>
Unlike	O
other	O
stack-based	O
environments	O
(	O
such	O
as	O
Forth	B-Application
and	O
the	O
Java	B-Language
virtual	I-Language
machine	I-Language
)	O
but	O
very	O
similar	O
to	O
a	O
real	O
target	O
CPU	O
,	O
the	O
p-System	B-Language
has	O
only	O
one	O
stack	B-Application
shared	O
by	O
procedure	O
stack	B-Application
frames	O
(	O
providing	O
return	B-Language
address	I-Language
,	O
etc	O
.	O
)	O
</s>
<s>
Three	O
of	O
the	O
machine	O
's	O
registers	B-General_Concept
point	O
into	O
the	O
stack	B-Application
(	O
which	O
grows	O
upwards	O
)	O
:	O
</s>
<s>
SP	O
points	O
to	O
the	O
top	O
of	O
the	O
stack	B-Application
(	O
the	O
stack	B-Application
pointer	O
)	O
.	O
</s>
<s>
MP	O
marks	O
the	O
beginning	O
of	O
the	O
active	O
stack	B-Application
frame	O
(	O
the	O
mark	O
pointer	O
)	O
.	O
</s>
<s>
EP	O
points	O
to	O
the	O
highest	O
stack	B-Application
location	O
used	O
in	O
the	O
current	O
procedure	O
(	O
the	O
extreme	O
pointer	O
)	O
.	O
</s>
<s>
Also	O
present	O
is	O
a	O
constant	O
area	O
,	O
and	O
,	O
below	O
that	O
,	O
the	O
heap	B-General_Concept
growing	O
down	O
towards	O
the	O
stack	B-Application
.	O
</s>
<s>
The	O
NP	O
(	O
the	O
new	O
pointer	O
)	O
register	O
points	O
to	O
the	O
top	O
(	O
lowest	O
used	O
address	O
)	O
of	O
the	O
heap	B-General_Concept
.	O
</s>
<s>
The	O
fifth	O
register	O
,	O
PC	O
,	O
points	O
at	O
the	O
current	B-General_Concept
instruction	I-General_Concept
in	O
the	O
code	O
area	O
.	O
</s>
<s>
Stack	B-Application
frames	O
look	O
like	O
this	O
:	O
</s>
<s>
where	O
n	O
specifies	O
the	O
difference	O
in	O
nesting	O
levels	O
(	O
remember	O
that	O
Pascal	B-Application
supports	O
nested	O
procedures	O
)	O
.	O
</s>
<s>
This	O
instruction	O
will	O
mark	O
the	O
stack	B-Application
,	O
i.e.	O
</s>
<s>
reserve	O
the	O
first	O
five	O
cells	O
of	O
the	O
above	O
stack	B-Application
frame	O
,	O
and	O
initialise	O
previous	O
EP	O
,	O
dynamic	O
,	O
and	O
static	O
link	O
.	O
</s>
<s>
This	O
will	O
save	O
the	O
PC	O
in	O
the	O
return	B-Language
address	I-Language
cell	O
,	O
and	O
set	O
the	O
procedure	O
's	O
address	O
as	O
the	O
new	O
PC	O
.	O
</s>
<s>
So	O
i	O
essentially	O
specifies	O
the	O
space	O
reserved	O
for	O
locals	O
(	O
plus	O
the	O
number	O
of	O
parameters	O
plus	O
5	O
)	O
,	O
and	O
j	O
gives	O
the	O
number	O
of	O
entries	O
needed	O
locally	O
for	O
the	O
stack	B-Application
.	O
</s>
<s>
with	O
C	O
giving	O
the	O
return	O
type	O
(	O
i	O
,	O
r	O
,	O
c	O
,	O
b	O
,	O
a	O
as	O
above	O
,	O
and	O
p	O
for	O
no	O
return	B-Language
value	I-Language
)	O
.	O
</s>
<s>
The	O
return	B-Language
value	I-Language
has	O
to	O
be	O
stored	O
in	O
the	O
appropriate	O
cell	O
previously	O
.	O
</s>
<s>
On	O
all	O
types	O
except	O
p	O
,	O
returning	O
will	O
leave	O
this	O
value	O
on	O
the	O
stack	B-Application
.	O
</s>
<s>
These	O
standard	O
procedures	O
are	O
Pascal	B-Application
procedures	O
like	O
readln( )	O
(	O
csp	O
rln	O
)	O
,	O
sin( )	O
(	O
csp	O
sin	O
)	O
,	O
etc	O
.	O
</s>
<s>
The	O
machine	O
had	O
3	O
registers	B-General_Concept
-	O
a	O
program	B-General_Concept
counter	I-General_Concept
p	O
,	O
a	O
base	O
register	O
b	O
,	O
and	O
a	O
top-of-stack	B-Application
register	I-Application
t	O
.	O
There	O
were	O
8	O
instructions	O
:	O
</s>
<s>
This	O
is	O
the	O
code	O
for	O
the	O
machine	O
,	O
written	O
in	O
Pascal	B-Application
:	O
</s>
<s>
This	O
machine	O
was	O
used	O
to	O
run	O
Wirth	O
's	O
PL/0	B-Language
,	O
a	O
Pascal	B-Application
subset	O
compiler	B-Language
used	O
to	O
teach	O
compiler	B-Language
development	O
.	O
</s>
<s>
P-Code	O
is	O
a	O
name	O
for	O
several	O
of	O
Microsoft	O
's	O
proprietary	O
intermediate	B-Application
languages	I-Application
.	O
</s>
<s>
They	O
provided	O
an	O
alternate	O
binary	O
format	O
to	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
Microsoft	B-Application
p-code	I-Application
was	O
used	O
in	O
Visual	B-Application
C++	I-Application
and	O
Visual	B-Language
Basic	I-Language
.	O
</s>
<s>
Like	O
other	O
p-code	O
implementations	O
,	O
Microsoft	B-Application
p-code	I-Application
enabled	O
a	O
more	O
compact	O
executable	B-Application
at	O
the	O
expense	O
of	O
slower	O
execution	O
.	O
</s>
