Successfully reported this slideshow.

More Related Content

Related Audiobooks

Free with a 14 day trial from Scribd

See all

P code

  1. 1. SYSTEM  SOFTWARE     PCODE     R.  V.  COLLEGE  OF  ENGINEERING     DEPARTMENT  OF  COMPUTER  SCIENCE  AND  ENGINEERING   (Autonomous  Institution  Affiliated  to  VTU)   Bangalore  –  560  059                      Assignment  Report  on  P-­‐Code  Compiler     Bachelor  of  Engineering   in   Computer Science & Engineering     By       Sandeep  R.V    1RV10CS089                                  (Academic  Year  :  2012-­‐13  )      
  2. 2. SYSTEM  SOFTWARE     PCODE     1. INTRODUCTION     Interpretive compilers are translators for high-level languages,  Such translators produce (as output) intermediate code (P-code for example) which is intrinsically simple enough to satisfy the constraints imposed by a practical interpreter, even though it may still be quite a long way from the machine code of the system on which it is desired to execute the original program. Rather than continue translation to the level of machine code, an alternative approach that may perform acceptably well is to use the intermediate code as part of the input to a specially written interpreter. This in turn "executes" the original algorithm, by simulating a virtual machine for which the intermediate code effectively is the machine code.                     Machine  Independent                      Machine  Dependent   Fig.  1.1     2.  P-­‐CODE     P-Code (Portable Code) is an assembly language for a hypothetical stack machine. One Such kind is Bytecode, bytecodes are compact numeric codes, constants, and references (normally numeric addresses), which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of, program objects. They therefore allow much better performance than direct interpretation of source code. The name bytecode stems from instruction sets, which have one byte opcodes, followed by optional parameters. Example: Java bytecode 3.  P-­‐CODE  COMPILER     n P-code compilers (also called bytecode compilers) are very similar in concept to interpreter n The source program is analyzed and converted into an intermediate form, which is then executed interpretively n With a P-code compiler, this intermediate forms is the machine language for a hypothetical machine, often called pseudo-machine n P-code object programs can be executed on any machine that has a P-code interpreter
  3. 3. SYSTEM  SOFTWARE     PCODE     n The P-code object program is often much smaller than a corresponding machine code (native code) program would be Fig 3.1 Translation and Execution Using a P-code Compiler 4. P-CODE MACHINE Portable code machine is a virtual machine designed to execute p-code. This term is applied both generically to all such machines (such as the Java Virtual Machine and MATLAB precompiled code), and to specific implementations, the most famous being the p- Machine of the Pascal-P system, particularly the UCSD Pascal implementation. 4.1. Machine architecture The P-code machine is similar to a conventional computer in that it consists of a processor and a memory. A major difference is that many operations performed by the processor involve the stack, which is part of memory. For example a procedure call entails manipulating various factors such as parameters and return addresses and these are held on the stack. The machine instructions, called P-code, are stored in the memory and accessed in the normal manner. The processor has a defined instruction set as well as five registers, which have distinct functions for controlling the instructions and the stack areas within the memory.
  4. 4. SYSTEM  SOFTWARE     PCODE     The registers are: . PC the program counter; . SP the stack pointer . MP the mark stack pointer; . NP the new pointer; . EP the extreme stack pointer. The program counter, PC, is a pointer to the current instruction being executed. Other registers are used to control the remaining area of memory - the data store. The data store is divided into three areas as shown in Fig. 4.1.1 Fig 4.1.1 The constants area is generated by the assembler and accessed by the code. The heap grows towards the low-numbered locations of store and the NP pointer points at free heap space. Data is put onto the heap during a call to the new procedure and removed by using mark and release. The stack area has a further internal structure and is used to hold stack frames. A stack frame is generated and placed on the stack each time a procedure or function is
  5. 5. SYSTEM  SOFTWARE     PCODE     called (in the following section, except where explicitly stated, references to procedures also include functions.) The first stack frame is the exception in that this belongs to the program block. The stack frames on the stack are shown in Fig. 4.1.2.

×