P-code machine
P- code is the instruction set of a pseudo - machine (or P- machine ), that is a virtual CPU executing code as the P- machine language. The P-code was a computer or CPU - independent code and was part of the development environment UCSD Pascal. The reaction in the machine language of the CPU is performed by the interpreter of the P machine. One can consider the P-code and the concept of the virtual machine as a spiritual forerunner of today's Java Virtual Machine.
Platforms
Due to the independence of specific computer architectures, the P- system could be ported to a variety of platforms:
- 6502 (Apple II)
- DEC LSI -11
- DEC PDP-11
- Zilog Z80 systems
- Motorola 68000
- Intel 8086 (IBM PC)
- Texas Instruments TMS9900 ( TI99 )
Functions of the P- machine
- Addressing of variables, strings, byte arrays
- Logical operations and comparisons
- Arithmetic with constants and variables of type integer, real, set, array, string
- Branches, jumps
- Procedure and function calls
- Overlay procedures
- System functions and procedures
Register the emulator
P machine is a 16-bit machine. The address space is limited to 64 KiB. But she is able to manage multiple address spaces, eg 128 KiB in version IV to emulate the P- codes, the following register ( pointer) are:
P- code ( instruction set of the P- machine )
If 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 instruction classes:
Connection between P- machine, and operating system
The UCSD Pascal operating system and the virtual P- machine exchange information via the system variable SYSCOM. This is located in the outer block of the operating system. This memory range is the P - machine 'known'.
P-code example
Excerpt from a decompiler Listing:
AttributeTable ------------------------- Procedure no. 37 Lex Level: 0 Enteric: 54 Exit IC: 7 Size parameter: 0 words Data Size: 2 words ------------------------- Block No: | 58 Block Offset: | 132 Offset P-code hex code 0 CBP 36 C224 LOD 2 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 CLEAR SCREEN; ( * Comment * ) BEGIN HOME CURSOR; (* Offset 0 *) WITH SYSCOM ^, CRTCTRL DO ( * offset 10 * ) BEGIN UNIT CLEAR (3); (* Offset 13 * ) IF ERASEEOS <> CHR ( 0) THEN (* offset 23 * ) PUTPREFIXED (3, ERASEEOS ) ( offset * 32 * ) ELSE (* offset 34 * ) PUTPREFIXED ( 6 CLEAR SCREEN ) (* offset 43 * ) END END (* CLEAR SCREEN *); (* Offset 45 * ) see also