#AS= /bin/as
#SEPFLAG= -i -X
#SEPFLAG=-i
-CFLAGS=-m32 -g -DLISTING
+CFLAGS=-m32 -g
-all: as
+all: as aslist asxlat
as: as0.o as2.o
# ${LD} ${SEPFLAG} -o $@ ${STAGEDIR}/lib/crt0.o as0.o as2.o -lc
# ${CC} ${SEPFLAG} -o $@ as0.o as2.o
${CC} ${CFLAGS} -o $@ as0.o as2.o
+as0.o: as0.c as0.h as2.h
+as2.o: as2.c as0.h as2.h
+
+aslist: aslist0.o aslist2.o
+ ${CC} ${CFLAGS} -o $@ aslist0.o aslist2.o
+
+aslist0.o: as0.c as0.h as2.h
+ ${CC} ${CFLAGS} -DLISTING -o $@ -c $<
+
+aslist2.o: as2.c as0.h as2.h
+ ${CC} ${CFLAGS} -DLISTING -o $@ -c $<
+
+asxlat: asxlat0.o asxlat2.o
+ ${CC} ${CFLAGS} -o $@ asxlat0.o asxlat2.o
+
+asxlat0.o: as0.c as0.h as2.h
+ ${CC} ${CFLAGS} -DTRANSLATE -o $@ -c $<
+
+asxlat2.o: as2.c as0.h as2.h
+ ${CC} ${CFLAGS} -DTRANSLATE -o $@ -c $<
+
install: all
- ${INSTALL} -s as ${DESTDIR}/bin
+ ${INSTALL} -s as aslist asxlat ${DESTDIR}/bin
clean:
- rm -f *.o a.out as core errs
+ rm -f *.o a.out as aslist asxlat core errs
int leftflags; /* r3 */
intptr_t token; /* r4 */
+#ifdef TRANSLATE
+static char xbuf[0x1000];
+static char *xbufp = xbuf, *xwhitep, *xstartp;
+static char *xstartpsave, *xbufpsave;
+static size_t xsavestartn, xsavebufn;
+static char xsave[0x1000];
+static size_t xrestn;
+static char xrest[0x1000];
+static int xlab, xlabnext;
+static int xlabb[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+static int xlabf[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+#endif
+
/* PDP-11 assembler */
/* _main: */
/* jsr r5,csv */
printf("pass 0\n");
#endif
pass0();
+#ifdef TRANSLATE
+ write(1, xbuf, xbufp - xbuf);
+#endif
/* flush the intermediate object file */
/* mov $1024.,-(sp) / write(fout, outbuf, 1024) */
/* br ealoop */
tokensave = token;
+#ifdef TRANSLATE
+ xstartpsave = xstartp;
+ xbufpsave = xbufp;
+#endif
p0readop();
if (token == TEQUAL)
goto equal;
if (token == TCOLON)
goto colon;
savop = token;
+#ifdef TRANSLATE
+ xsavestartn = xstartp - xbufpsave;
+ xsavebufn = xbufp - xbufpsave;
+ memcpy(xsave, xbufpsave, xsavebufn);
+#endif
token = tokensave;
+#ifdef TRANSLATE
+ xstartp = xstartpsave;
+ xbufp = xbufpsave;
+#endif
p0opline();
goto ealoop;
label = fbcheck(numval);
curfbr[label] = pdot->flags;
curfb[label] = pdot->value;
+#ifdef TRANSLATE
+ if (xlabf[label] == -1)
+ xlab = xlabnext++;
+ else {
+ xlab = xlabf[label];
+ xlabf[label] = -1;
+ }
+ xlabb[label] = xlab;
+ if (xstartp >= xbuf + 0xff0)
+ abort();
+ xbufp = xstartpsave + sprintf(xstartpsave, "_%d:", xlab);
+#endif
/* cmp fbfree,$4 / room for another fb entry? */
/* bge 5f / yes - br */
/* printf("leftflags 0%o pdot->flags 0%o\n", leftflags, pdot->flags); */
if (leftflags != pdot->flags)
goto doterr;
+#ifdef TRANSLATE
+ xrestn = xbufp - xwhitep;
+ memcpy(xrest, xwhitep, xrestn);
+ if (xstartpsave + xrestn >= xbuf + 0xff0)
+ abort();
+ xbufp = xstartpsave + sprintf(xstartpsave, ".ds\t%d", leftvalue);
+ memcpy(xbufp, xrest, xrestn);
+ xbufp += xrestn;
+#endif
}
/* bicb $37,(r1) */
*p++ = 0;
/* printf("symbol = \"%s\"\n", symbol); */
ch = c;
+#ifdef TRANSLATE
+ if (xbufp <= xbuf)
+ abort();
+ --xbufp;
+#endif
/* if (ch) printf("a push 0x%02x\n", ch); */
/* mov (sp)+,r1 */
/* mov r1,r0 */
ch = c;
+#ifdef TRANSLATE
+ if (xbufp <= xbuf)
+ abort();
+ --xbufp;
+#endif
/* if (ch) printf("b push 0x%02x\n", ch); */
numbervalue = octal;
if (ch) {
c = ch;
ch = 0;
+#ifdef TRANSLATE
+ //if (xbufp > xbuf && xbufp[-1] == '\n') {
+ // write(1, xbuf, xbufp - xbuf);
+ // xbufp = xbuf;
+ //}
+ //else
+ if (xbufp >= xbuf + 0x1000)
+ abort();
+ *xbufp++ = c;
+#endif
return c;
}
/* putchar(c); */
if (c == 0)
continue;
+#ifdef TRANSLATE
+ //if (xbufp > xbuf && xbufp[-1] == '\n') {
+ // write(1, xbuf, xbufp - xbuf);
+ // xbufp = xbuf;
+ //}
+ //else
+ if (xbufp >= xbuf + 0x1000)
+ abort();
+ *xbufp++ = c;
+#endif
return c;
/* 2: */
int c;
/* printf("p0readop() savop = 0x%08x\n", savop); */
+#ifdef TRANSLATE
+ xwhitep = xbufp;
+#endif
if (savop) {
token = savop;
savop = 0;
+#ifdef TRANSLATE
+ if (xbufp + xsavebufn >= xbuf + 0x1000)
+ abort();
+ memcpy(xbufp, xsave, xsavebufn);
+ xstartp = xbufp + xsavestartn;
+ xbufp = xbufp + xsavebufn;
+#endif
return;
}
/* jmp *1f-2(r1) */
while (1) {
+#ifdef TRANSLATE
+ xstartp = xbufp;
+#endif
c = rch();
switch (chartab[c]) {
default:
/* skip */
case -006:
+#ifdef TRANSLATE
+ xbufp[-1] = ';';
+#endif
skip();
return;
void rdname(c) int c; {
ch = c;
+#ifdef TRANSLATE
+ if (xbufp <= xbuf)
+ abort();
+ --xbufp;
+#endif
/* if (ch) printf("c push 0x%02x\n", ch); */
if (c >= '0' && c <= '9')
rdnum();
int flags;
/* printf("p0opline() token 0x%08x\n", token); */
+#if 0 //def TRANSLATE
+ *xbufp = 0;
+ printf("p0opline() token 0x%08x xstartp \"%s\"\n", token, xstartp);
+ fflush(stdout);
+#endif
+
if (token >= 0 && token < TASCII) {
if (token == TSTRING)
p0opl17();
p0xpr();
return;
}
+#ifdef TRANSLATE
+ if (xstartp >= xbuf + 0xff0)
+ abort();
+ switch (flags) {
+ case FDOTTEXT:
+ xbufp = xstartp + sprintf(xstartp, ".area TEXT");
+ break;
+ case FDOTDATA:
+ xbufp = xstartp + sprintf(xstartp, ".area DATA");
+ break;
+ case FDOTBSS:
+ xbufp = xstartp + sprintf(xstartp, ".area BSS");
+ break;
+ }
+#endif
+
/* mov r0,-(sp) */
/* jsr pc,p0readop */
p0amin();
return;
case TDOLL:
+#ifdef TRANSLATE
+ xbufp[-1] = '#';
+#endif
p0adoll();
return;
case TSTAR:
/* rts pc */
void p0amin() {
+#ifdef TRANSLATE
+ xstartpsave = xstartp;
+ xbufpsave = xbufp;
+#endif
p0readop();
if (token != TLPAREN) {
savop = token;
+#ifdef TRANSLATE
+ xsavestartn = xstartp - xbufpsave;
+ xsavebufn = xbufp - xbufpsave;
+ memcpy(xsave, xbufpsave, xsavebufn);
+#endif
token = TMIN;
+#ifdef TRANSLATE
+ xstartp = xstartpsave;
+ xbufp = xbufpsave;
+#endif
p0getx();
}
else {
if (token >= TLABEL) {
if (token < TLABEL + 10) {
+#ifdef TRANSLATE
+ if (xstartp >= xbuf + 0xff0)
+ abort();
+ xbufp = xstartp + sprintf(xstartp, "_%d", xlabb[token - TLABEL]);
+#endif
rightflags = curfbr[token - TLABEL];
/* bug!! should be rightvalue / rightflags below: */
leftvalue = curfb[token - TLABEL];
error('f');
}
else {
+#ifdef TRANSLATE
+ xlab = token - (TLABEL + 10);
+ if (xlab < 10) {
+ if (xlabf[xlab] == -1)
+ xlabf[xlab] = xlabnext++;
+ if (xstartp >= xbuf + 0xff0)
+ abort();
+ xbufp = xstartp + sprintf(xstartp, "_%d", xlabf[xlab]);
+ }
+#endif
leftflags = 0;
leftvalue = 0;
}