p code

from Wikipedia, the free encyclopedia

P-code is the instruction set of a pseudo-machine (or P-machine), i.e. a virtual CPU that executes P-code as machine language . The P-Code was a computer or CPU-independent code and was part of the UCSD Pascal development environment . The implementation in the machine language of the CPU is done by the interpreter of the P machine. The P-Code and the concept of the virtual machine can be seen as the intellectual forerunners of today's Java Virtual Machine .

Platforms

As it is independent of certain computer architectures, the P-System could be ported to a wide variety of platforms:

Functional scope of the P machine

Register of the emulator

The P machine is a 16-bit machine; the address space is therefore limited to 64 KiB. However, it is able to manage several address spaces, for example 128 KiB in version IV. The following registers ( pointers ) are used to emulate the P code :

SP : Stack pointer Pointer to the top word in the stack . Used to pass parameters and as an operand source for the interpreter .
IPC : Interpreter Program Counter Address of the next P-code instruction in the code segment of the current procedure
SEG : Segment pointer Pointer to the procedure directory of the current segment
JTAB : Jump table pointer Pointer to the jump table of the current segment
KP : Program stack pointer Pointer to the end of the program stack
MP : Markstack pointer Pointer to the activation record of the current procedure for access to the local variables
NP : New pointer Pointer to the end of the dynamic heap
BASE : Base Procedure Pointer to the activation record of the basic procedure for access to the global variables

P code (instruction set of the P machine)

The instruction code of the pseudo-machine is one or two bytes long and is followed by up to four operands . There are the following command classes:

  • 1-word transport commands
  • Multi-word transport commands
  • Byte array handling
  • String treatment
  • Record and array handling
  • Dynamic memory allocation
  • Arithmetic commands
  • Jump commands
  • Procedure and function calls
  • Support routines

Connection between P machine and operating system

The UCSD-Pascal - operating system and the virtual P-machine exchange information on the system variable SYSCOM out. This is located in the outer block of the operating system. This memory area is "known" to the P machine.

P-code example

Extract from a disassembler listing:

Attribute Table
-------------------------
Procedure No.:   37
Lex Level:        0
EnterIC:         54
Exit IC:          7
Parameter Size:   0 words
Data Size:        2 words
-------------------------
Block No:|58
Block Offset:|132

Offset P-Code             Hex-Code
     0 CBP     36         C224
     2 LOD      1     1   B60101
     5 SRO      1         AB01
     7 SLDO1              E4
     8 INC     31         A21F
    10 SRO      2         AB02
    12 SLDC3              03
    13 CSP   UNITCLEA     9E26
    15 SLDO2              E9
    16 INC 1              A201
    18 SLDC8              08
    19 SLDC0              00
    20 LDP                BA
    21 SLDC0              00
    22 NEQI               CB
    23 FJP     36         A10B
    25 SLDC3              03
    26 SLDO2              E9
    27 INC      1         A201
    29 SLDC8              08
    30 SLDC0              00
    31 LDP                BA
    32 CBP     52         C234
    34 UJP     45         B909
    36 SLDC6              06
    37 SLDD02             E9
    38 INC      4         A204
    40 SLDC8              08
    41 SLDC8              08
    42 LDP                BA
    43 CBP     52         C234
    45 RBP      0         C100

In UCSD-Pascal the procedure looks like this:

PROCEDURE CLEARSCREEN;                (*Bemerkung*)
  BEGIN HOMECURSOR;                   (*Offset  0*)
    WITH SYSCOM^,CRTCTRL DO           (*Offset 10*)
      BEGIN
        UNITCLEAR(3);                 (*Offset 13*)
        IF ERASEEOS <> CHR(0) THEN    (*Offset 23*)
          PUTPREFIXED(3,ERASEEOS)     (*Offset 32*)
        ELSE                          (*Offset 34*)
          PUTPREFIXED(6,CLEARSCREEN)  (*Offset 43*)
      END
END (*CLEARSCREEN*) ;                 (*Offset 45*)

See also

Web links