XTRAN Example — Translate Encore (SEL, Gould) Assembler to C
The following example uses the standard set of XTRAN rules for parsing Encore assembler and translating it to C.
NOTE that the translation shown below was done with default conditions. XTRAN provides many options for controlling the way it translates.
We have declared to XTRAN the following C structure prior to translation:
typedef struct { short off1; } Str;
Process Flowchart
Here is a flowchart for this process, in which the elements are color coded:
- BLUE for XTRAN versions (runnable programs)
- ORANGE for XTRAN rules (text files)
- RED for
code
Input to XTRAN:
WRD2 DC 2 OFF1 EQU 4 * * Show off various addressing modes: * START LW 1,WRD1 LW 1,WRD1 LW 1,WRD1(4) LW 1,WRD1(4) LW 1,WRD1,2 LW 1,WRD1,2 LW 1,*WRD1 LW 1,*WRD1 LW 1,*WRD1(3) LW 1,*WRD1(3) LW 1,*WRD1,2 LW 1,*WRD1,2 LW 2,OFF1(4) LW 2,OFF1(4) LW 2,OFF1,2 LW 2,OFF1,2 LW 2,*OFF1(3) LW 2,*OFF1(3) LW 2,*OFF1,2 LW 2,*OFF1,2 * * Now show off some different instructions: * TRR 1,2 LRR 1,2 LMW 2,WRD1(3) LMW 2,WRD1(3) LNW 2,WRD1,1 LNW 2,WRD1,1 LI 1,100 LI 1,100 LEA 1,WRD1 LEA 1,WRD1 LA 1,WRD1 LA 1,WRD1 LABR 5,WRD2 LABR 5,WRD2 SUABR 5,WRD1 SUABR 5,WRD1 STWBR 3,WRD2 STWBR 3,WRD2 STW 4,WRD1(3) STW 4,WRD1(3) ZMW WRD1 ZMW WRD1 ZR 4 ZR 4
Output from XTRAN:
extern union /*unionize r1*/ { long l; long *p_l; } r1; extern union /*unionize br4*/ { long l; Str *p__Str; } br4; extern union /*unionize r2*/ { long l; Str *p__Str; } r2; extern union /*unionize br3*/ { long l; Str *p__Str; } br3; extern union /*unionize br5*/ { long *p_l; long l; } br5; extern long r4; long wrd1 = 1; long wrd2 = 2; typedef struct str { long off1; } Str; start: /* * * Show off various addressing modes: * */ r1.l = wrd1; /*lw 1,wrd1*/ r1.l = wrd1[br4.l / 4]; /*lw 1,wrd1(4)*/ r1.l = wrd1[r2.l / 4]; /*lw 1,wrd1,2*/ r1.l = *wrd1; /*lw 1,*wrd1*/ r1.l = *wrd1[br3.l / 4]; /*lw 1,*wrd1(3)*/ r1.l = *wrd1[r2.l / 4]; /*lw 1,*wrd1,2*/ r2.l = br4.p__Str->off1; /*lw 2,off1(4)*/ r2.l = r2.p__Str->off1; /*lw 2,off1,2*/ r2.l = *br3.p__Str->off1; /*lw 2,*off1(3)*/ r2.l = *r2.p__Str->off1; /*lw 2,*off1,2*/ /* * * Now show off some different instructions: * */ r2.l = r1.l; /*lrr 1,2*/ r2.l = wrd1[br3.l / 4] & r4; /*lmw 2,wrd1(3)*/ r2.l = -wrd1[r1.l / 4]; /*lnw 2,wrd1,1*/ r1.l = 100; /*li 1,100*/ r1.p_l = &wrd1; /*lea 1,wrd1*/ r1.p_l = &wrd1; /*la 1,wrd1*/ br5.p_l = &wrd2; /*labr 5,wrd2*/ br5.l -= &wrd1; /*suabr 5,wrd1*/ wrd2 = br3.l; /*stwbr 3,wrd2*/ wrd1[br3.l / 4] = r4; /*stw 4,wrd1(3)*/ wrd1 = 0; /*zmw wrd1*/ r4 = 0; /*zr 4*/