Digital Signal Processing Reference
In-Depth Information
Fig. 4 Simulator generation
for compiled simulation
3.1
Basic Principles
All compiled simulators are based on the following principle; see Fig. 4 for an
overview. The binary or the assembly language source of the application to be
simulated is read by the simulator generator. The generator then translates the
application to a high-level language, such as C or C++. The generated source code
is translated to machine code by an optimizing high-level language compiler of
the host computer and linked against a generic simulator library. The resulting
program is a simulator, which emulates the behavior of the original application when
executed. In addition to the optimizations available to the host's high-level language
compiler, optimizations might be applicable during the source code generation by
the simulator generator, e.g., the generator may monitor execution modes of the
processor and thus omit certain simulation overhead.
Compiled simulators are distinguished by the way in which sequences of
instructions are translated to high-level language snippets. Mills [ 45 ] translates the
whole application available in assembly language source to a single function of the
C programming language. Each assembly language instruction is represented by a
C macro which emulates the behavior of the particular instruction. The macro uses
the original address of the instruction as a label of a C switch statement and is
followed by C statements which emulate the instruction. The macros
#define SUB(addr) case (addr): AC -= * SP++;
#define BNE(addr, to) case (addr): if (AC) { PC = (to); break; }
define subtract and branch instructions for an accumulator architecture. The variable
PC corresponds to the program counter of the emulated architecture. The macros
are used in a giant C switch statement which represents the whole instruction
memory of the emulated architecture (see Fig. 5 ) . The program counter has to be set
and evaluated in the switch statement only when a branch instruction is emulated.
The macros read like the original program.
Mills' method works very well for medium sized programs. The whole program
is translated to a single large C function. The advantage is that this function can
be compiled to very efficient machine code. Local variables of the function will
 
 
Search WWH ::




Custom Search