📄 outas68.c
字号:
outcol = 0;
gentype = nogen;
}
if (phiused && !phiput)
fputc(0x1f,outputFile);
}
}
/* Put an opcode
*/
void outop(char *name)
{
fputc('\t',outputFile);
while (*name)
fputc(toupper(*name++),outputFile);
}
void putop(int op)
{
if (op > op_ftwotox)
DIAG("illegal opcode.");
else
outop(oplst[op].word);
}
void putconst(ENODE *offset)
/*
* put a constant to the outputFile file.
*/
{ switch( offset->nodetype )
{
case en_autoreg:
case en_autocon:
case en_icon:
case en_lcon:
case en_iucon:
case en_lucon:
case en_ccon:
case en_absacon:
fprintf(outputFile,"$%lX",offset->v.i);
break;
case en_rcon:
case en_fcon:
case en_lrcon:
fprintf(outputFile,"%f",offset->v.f);
break;
case en_labcon:
case en_nalabcon:
fprintf(outputFile,"L_%ld",offset->v.i);
break;
case en_napccon:
case en_nacon:
fprintf(outputFile,"%s",offset->v.p[0]);
break;
case en_add:
putconst(offset->v.p[0]);
fprintf(outputFile,"+");
putconst(offset->v.p[1]);
break;
case en_sub:
putconst(offset->v.p[0]);
fprintf(outputFile,"-");
putconst(offset->v.p[1]);
break;
case en_uminus:
fprintf(outputFile,"-");
putconst(offset->v.p[0]);
break;
default:
DIAG("illegal constant node.");
break;
}
}
void putlen(int l)
/*
* append the length field to an instruction.
*/
{ switch( l )
{
case 0:
break; /* no length field */
case 1:
fprintf(outputFile,".B");
break;
case 2:
fprintf(outputFile,".W");
break;
case 4:
fprintf(outputFile,".L");
break;
case 6:
fprintf(outputFile,".S");
break;
case 8:
fprintf(outputFile,".D");
break;
case 10:
fprintf(outputFile,".X");
break;
default:
DIAG("illegal length field.");
break;
}
}
void putamode(AMODE *ap)
/*
* outputFile a general addressing mode.
*/
{ int scale,t;
switch( ap->mode )
{
case am_sr:
fprintf(outputFile, "SR");
break;
case am_bf:
fprintf(outputFile," {%d:%d}",ap->preg,ap->sreg);
break;
case am_divsl:
fprintf(outputFile,"D%d:D%d",ap->preg, ap->sreg);
break;
case am_immed:
fprintf(outputFile,"#");
case am_direct:
putconst(ap->offset);
break;
case am_adirect:
fputc('(',outputFile);
putconst(ap->offset);
fputc(')',outputFile);
putlen(ap->preg);
break;
case am_areg:
fprintf(outputFile,"A%d",ap->preg);
break;
case am_dreg:
fprintf(outputFile,"D%d",ap->preg);
break;
case am_freg:
fprintf(outputFile,"FP%d",ap->preg);
break;
case am_ind:
fprintf(outputFile,"(A%d)",ap->preg);
break;
case am_ainc:
fprintf(outputFile,"(A%d)+",ap->preg);
break;
case am_adec:
fprintf(outputFile,"-(A%d)",ap->preg);
break;
case am_indx:
fprintf(outputFile,"(");
putconst(ap->offset);
fprintf(outputFile,",A%d)",ap->preg);
break;
case am_pcindx:
fprintf(outputFile,"(");
putconst(ap->offset);
fprintf(outputFile,",PC)");
break;
case am_baseindxdata:
scale = 1;
t = ap->scale;
while (t--)
scale <<=1;
fprintf(outputFile,"(");
putconst(ap->offset);
if (ap->preg != -1)
fprintf(outputFile,",A%d",ap->preg);
fprintf(outputFile,",D%d.L",ap->sreg);
if (scale != 1)
fprintf(outputFile,"*%d",scale);
fputc(')', outputFile);
break;
case am_baseindxaddr:
scale = 1;
t = ap->scale;
while (t--)
scale <<=1;
fprintf(outputFile,"(");
putconst(ap->offset);
if (ap->preg != -1)
fprintf(outputFile,",A%d",ap->preg);
fprintf(outputFile,",A%d.L",ap->sreg);
if (scale != 1)
fprintf(outputFile,"*%d",scale);
fputc(')', outputFile);
break;
case am_mask:
put_mask((int)ap->offset, ap->preg);
break;
case am_fmask:
put_fmask((int)ap->offset, ap->preg);
break;
default:
DIAG("illegal address mode.");
break;
}
}
void put_code(OCODE *cd)
/*
* outputFile a generic instruction.
*/
{
int op = cd->opcode,len = cd->length;
AMODE *aps = cd->oper1,*apd = cd->oper2, *ape = cd->oper3;
nl();
if (!prm_asmfile) {
;/* oc_putop(cd); */
return;
}
if (op == op_line) {
if (!prm_lines)
return;
fprintf(outputFile,";\n; Line %d:\t%s\n;\n",len,(char *)aps);
return;
}
if (op == op_slit) {
int l =genstring((char *)cd->oper1,(int)cd->oper2);
if ((int)cd->oper2)
genword(0);
else {
if (!(l & 1))
genbyte(0);
genbyte(0);
}
return;
}
if( op == op_dcl)
{
putop(op);
putlen(len);
fprintf(outputFile,"\t");
putamode(aps);
if (prm_rel)
fprintf(outputFile,"-*");
fprintf(outputFile,"\n");
return;
}
else
{
putop(op);
putlen(len);
}
if( aps != 0 )
{
fprintf(outputFile,"\t");
putamode(aps);
if( apd != 0 )
{
if (apd->mode != am_bf)
fprintf(outputFile,",");
putamode(apd);
if (ape) {
if (ape->mode != am_bf)
fprintf(outputFile,",");
putamode(ape);
}
}
}
fprintf(outputFile,"\n");
}
void put_fmask(int mask, int reverse)
/*
* generate a register mask for floating restore and save.
*/
{
unsigned put = FALSE,i,bit;
if (!reverse) {
bit = 0x80;
for (i=0; i < 8; i++) {
if (bit & (unsigned) mask) {
if (put)
fputc('/', outputFile);
put = TRUE;
putreg(i+16);
}
bit >>= 1;
}
}
else{
bit = 1;
for (i=0; i < 8; i++) {
if (bit & (unsigned)mask) {
if (put)
fputc('/', outputFile);
put = TRUE;
putreg(i+16);
}
bit <<= 1;
}
}
}
void put_mask(int mask, int reverse)
/*
* generate a register mask for integer restore and save.
*/
{
unsigned put = FALSE,i,bit;
if (!reverse) {
bit = 0x8000;
for (i=0; i < 16; i++) {
if (bit & (unsigned) mask) {
if (put)
fputc('/', outputFile);
put = TRUE;
putreg(i);
}
bit >>= 1;
}
}
else{
bit = 1;
for (i=0; i < 16; i++) {
if (bit & (unsigned)mask) {
if (put)
fputc('/', outputFile);
put = TRUE;
putreg(i);
}
bit <<= 1;
}
}
}
void putreg(int r)
/*
* generate a register name from a tempref number.
*/
{ if( r < 8 )
fprintf(outputFile,"D%d",r);
else if (r <16)
fprintf(outputFile,"A%d",r - 8);
else fprintf(outputFile,"FP%d",r-16);
}
void gen_strlab(SYM *sp)
/*
* generate a named label.
*/
{
datasp = sp;
if (prm_asmfile) {
nl();
if (curseg == codeseg && currentfunc->pascaldefn) {
char buf[100],*q=buf,*p=sp->name;
if (prm_cmangle)
p++;
while(*p)
*q++=toupper(*p++);
*q++ = 0;
fprintf(outputFile,"%s:\n",buf);
}
else
fprintf(outputFile,"%s:\n",sp->name);
}
else
;/* oc_namedlab(sp); */
dataofs = 0;
}
void put_label(OCODE *cd)
/*
* outputFile a compiler generated label.
*/
{
if (prm_asmfile) {
nl();
fprintf(outputFile,"L_%ld:\n",(long)(cd->oper1));
}
else
;/* oc_unnamedlab(cd); */
}
void put_staticlabel(long label)
{
if (prm_asmfile) {
nl();
fprintf(outputFile,"L_%ld:\n",label);
}
}
void genfloat(float val)
/*
* Output a float value
*/
{ if (prm_asmfile)
if( gentype == floatgen && outcol < 60) {
fprintf(outputFile,",%f",val);
outcol += 8;
}
else {
nl();
fprintf(outputFile,"\tDC.S\t%f",val);
gentype = floatgen;
outcol = 19;
}
else
;/* oc_genfloat(val); */
dataofs+=4;
}
void gendouble(double val)
/*
* Output a double value
*/
{ if (prm_asmfile)
if( gentype == doublegen && outcol < 60) {
fprintf(outputFile,",%f",val);
outcol += 8;
}
else {
nl();
fprintf(outputFile,"\tDC.D\t%f",val);
gentype = doublegen;
outcol = 19;
}
else
;/* oc_gendouble(val); */
dataofs+=8;
}
void genlongdouble(long double val)
/*
* Output a double value
*/
{ if (prm_asmfile)
if( gentype == longdoublegen && outcol < 60) {
fprintf(outputFile,",%f",val);
outcol += 8;
}
else {
nl();
fprintf(outputFile,"\tDT\t%f",val);
gentype = longdoublegen;
outcol = 19;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -