Elmo HARSFEN0602 Virtual Machines, Virtual Machine registers, Call Stack During Function Call

Models: HARmonica HARSFEN0602

1 220
Download 220 pages 51.63 Kb
Page 73
Image 73

HARSFEN0602ElmoHARmonicaSoftwareManual

PRELIMINARYDRAFT

7 The Virtual Machines

71

7.1.1Introduction Alla please complete where necessary

The Harmonica can run user program, as explained in the Chapter "The Harmonica User Programming Language". Although the user program runs syntactically the same statements as the interpreter, the processing mechanism is totally different.

The interpreter analyses text on line. The user program does not – it runs a compiled code. The most important advantage is that all the text analysis can be spared in real-time, boosting the user program performance. Another advantage is that future user syntax improvements are possible without upgrading the amplifier software.

An external tool, called "The Harmonica Compiler" compiles the user text. The compiler outputs a file of short and simple binary commands.

Take for example the user text DC=AC+1000;

This code is translated to

.... Alla please fill.

The texts of the compiled version above are in a mnemonic form. Each mnemonic represents an opcode of fixed structure, as described below. In hexadecimal form, the example piece of code is

.... Alla please fill.

The compiled code looks much like an assembly language. The "CPU" that runs this assembly language is written in DSP software. This software that implements the "User Program CPU" is called a "Virtual Machine".

A virtual machine behaves much like a CPU – it has a stack, a code segment with program counter, and a data memory segment.

The Harmonica is designed with multiple virtual machines, so that several user programs may be run in parallel.

The machines are not completely similar. Only one machine, called the Main machine, is interrupted by automatic routines. The other machines are not interrupted by automatic routines. If one desires to interrupt another machine, he may write a software interrupt to that machine from the automatic routine handler of the main machine.

The first release allows the user to activate only one (the Main) virtual machine.

7.2Virtual Machine registers

A virtual machine has the following registers:

Register

Description

Comment

SP

Stack pointer

Points to top of stack.

BP

Base pointer

Freezes the value of the stack pointer

 

 

when a function is entered. BP is

 

 

used to refer local variables of a

 

 

function.

PC

Program counter

Points to the code position now

 

 

executing.

7.3Call Stack During Function Call

Consider a call stack during a function call (the opcode is USRSUBJ). Assume that a user defines a function :

function [float x, float y, float z] = f (int a, int b, int c, ind d) ; % Prototype Assume that a function call is:

Page 73
Image 73
Elmo HARSFEN0602, HARmonica software manual Virtual Machines, Virtual Machine registers, Call Stack During Function Call