Page 107 - Mechatronic Systems Modelling and Simulation with HDLs
P. 107
96 5 SOFTWARE IN HARDWARE DESCRIPTION LANGUAGES
/* Start time = 0, first call:
Initialise debugger, logger, context etc.
Fill the main memory with the programme */
c1->m[256] = 182; c1->m[257] = 16;
c1->m[258] = 205; c1->m[259] = 1; c1->m[260] = 20;
c1->m[268] = 32; c1->m[269] = 3;
...
/* Initialise context ... */
c1->pc = 256*c1->m[MEMORYSIZE-2] + k1->m[MEMORYSIZE-1];
c1->ac = 0; c1->ix = 0; c1->sp = 511; c1->cc = 0;
...
goto hub;
/* Assembler programme in C ... */
l0256: /* lda, Load Accumulator, direct addr. */
debugger(...); /* Control debugger */
if (is_io(c1->m[c1->pc+1]))/* IO or main memory? */
c1->ac=fetch_io(c1->m[c1->pc+1]);/* IO access */
else
c1->ac=c1->m[c1->m[c1->pc+1]];/* Main memory access */
c1->cyc+=3; c1->pc+=2; /* Increment cyc, pc */
set_flags(...); /* Update the flags */
t_cur=c1->cyc*CYCTIME; /* Update the time */
l0258: /* jsr, Jump Subroutine, ext. addr. */
debugger(...); /* Control debugger */
c1->m[c1->sp--]=(c1->pc+3)%256;/* Protect return */
c1->m[c1->sp--]=(c1->pc+3)/256;/* address on stack */
c1->pc=256*k1->m[c1->pc+1]+c1->m[c1->pc+2];/* Set pc */
c1->cyc+=5; /* Increment cyc */
t_cur=c1->cyc*CYCTIME; /* Update time */
goto hub; /* Initiate the jump */
l0261: /* bra, Branch, relative addressing */
debugger(...); /* Control debugger */
c1->pc=c1->pc+2+c1->m[c1->pc+1]>127 ?/* Calculate rel. */
(-(256-c1->m[c1->pc+1])):(c1->m[c1->pc+1]);/* jump */
c1->cyc+=3; /* Increment cyc */
t_cur=c1->cyc*CYCTIME; /* Update time */
goto hub; /* Initiate the jump */
...
hub:
switch(c1->pc) {
case 256: goto l0256;
case 258: goto l0258;
case 261: goto l0261;
...
}}}
Programme 5.2 Simplified software model in programming language C