The invention relates to a method for executing a source program on a processing unit comprising a predetermined microcontroller core for executing native instructions from a predetermined set of micro-controller specific instructions; the method comprising:
a pre-processing step of expressing program statements of the source program in a sequence of instructions comprising virtual machine instructions; and storing the sequence of instructions in an instruction memory; and PA1 an execution step of fetching instructions from the instruction memory; using conversion means of the processing unit to convert virtual instructions fetched from the instruction memory into native instructions; and feeding the native instructions to the microcontroller core for execution. PA1 a predetermined microcontroller core for executing native instructions from a predetermined set of micro-controller specific instructions; the native instructions being different from the virtual machine instructions; PA1 an instruction memory for storing instructions including at least one of the virtual machine instructions; PA1 a converter comprising conversion means for converting a virtual machine instruction fetched from the instruction memory into at least one native instruction for execution by the microcontroller core. PA1 defining for the program-specific virtual machine an associated conversion means for converting virtual machine instructions of the program-specific virtual machine into native instructions of the microcontroller core; and PA1 representing the associated conversion means in the processing unit. According to the invention, a program-specific virtual machine is defined for a program such that the program can be expressed in a form which is more compact than if the program was expressed in native instructions of the core. Also an associated conversion means is defined. The conversion means may for instance be implemented using a conversion table or microcode stored in ROM or dedicated logic, such as a PLD. The defined conversion means is represented in the processing unit. In this way, fast execution of the program is maintained, whereas at the same time a compact representation is achieved. This method is particularly suitable for use with embedded applications. In this case, the source program relates to all program statements initially represented in the embedded system (for instance, the program present in the system when the user purchases the system). The program may be stored in a permanent memory, such as ROM, or stored in a reprogrammable memory, such as EEPROM. For embedded applications it is highly desired that the code used to represent the embedded application program is compact and that the performance in executing the code is good. Typically, processing units used for embedded applications are based on a family concept, where for a specific application a processing unit is created from a given microcontroller core and I/O or storage components required for the application. It is desired to make no or at least no significant modifications to the core or the components in order to reduce costs. According to the invention, on the one hand virtual machine instructions are defined specifically for the program, giving full flexibility in achieving code compaction, whereas on the other hand an off-the-shelf core is used for executing the program. The required conversion from virtual machine instructions to native instructions is performed by a conversion means, which can be seen as a kind of pre-processor.
The invention further relates to a processing unit for executing instructions of a virtual machine, the instructions being referred to as virtual machine instructions; the processing unit comprising:
Increasingly, source programs are expressed in (compiled to) instructions of a virtual machine instead of native instructions of a microcontroller core on which the program is to be executed. A main reason for using a virtual machine is portability of programs between different machines (platforms). A program expressed in the virtual machine instructions of the virtual machine can be executed relatively easily on several concrete machines, using suitable interpreters operating on those machines. At this moment a driving force for using portable programs is Java, where Java programs are exchanged via Internet and can be executed on different native machines using processors with different instruction sets. Using a compiler, Java programs are expressed in Java byte codes (JBCs), which form the instructions of the Java Virtual Machine. The resulting code is usually referred to as a Java applet.
Conventionally, programs expressed in virtual machine instructions are executed by means of software interpretation. The processor (CPU) executes a special interpreter program, where in a loop the processor fetches a virtual machine instruction, decodes it into a sequence of native instructions of the microcontroller core of the processor and executes each native instruction. This technique is slow and requires an additional interpreter program, which can be relatively large. To improve the execution speed, the so-called Just-In-Time (JIT) compilation technique is used. Just before starting execution of software module expressed in virtual machine instructions, the module is compiled to native code (i.e., expressed in native machine instructions). In this way, the module needs to be stored twice in addition to the code for the compiler. The additional storage requirements of software interpretation are not desired for embedded systems. To avoid performance and storage overhead, it is preferred to use a hardware interpreter. In itself a hardware interpreter is known in the form of a Prolog pre-processor for Warren's abstract instruction set. In the paper "A Prolog pre-processor for Warren's abstract instruction set" by B. Knodler and W. Rosenstiel, Microprocessing and Microprogramming 18 (1986) pages 71-81, a pre-processor is described for interpreting programs written in the Prolog programming language on a Motorola 68000 processor (MC68000). A compiler is used to translate the Prolog source program into instructions, which have been defined by Mr. Warren and which are generally used for executing Prolog programs. The set of Warren instructions forms a virtual machine designed for executing Prolog programs. The sequence of Warren instructions resulting from the compilation are loaded into RAM and executed by the MC68000 with the aid of the pre-processor. After power-on, the MC68000 first performs a booting procedure by executing native MC68000 instructions. At the end of the booting procedure, the MC68000 is ready to initiate the execution of a Prolog program. This is started by jumping to a predetermined address range. The pre-processor is a memory-mapped device, which is mapped to this range. When the pre-processor is addressed it reads a Warren instruction (of the translated Prolog program) from its own RAM, adaptively synthesizes a sequence of MC68000 instructions and constants and sends these directly to the CPU for execution. The MC68000 instructions for each Warren instruction are stored in ROM of the pre-processor. In general, the pre-processor translates one Warren instruction into a sequence of MC68000 instructions. The pre-processor contains its own RAM controller and ROM controller, which generate the addresses for the RAM and ROM of the pre-processor. The RAM controller manages the RAM instruction pointer. Each successive read operation of the MC68000 results in the pre-processor sending the next instruction (and optional constants) of the sequence to the CPU. If the sequence has been completed, a next read operation results in the first instruction of the sequence corresponding to the next Warren instruction of the program being send to the CPU. The known pre-processor supports one virtual machine (the Warren machine).