ack/mach/pdp/as/mach5.c

133 lines
2.2 KiB
C
Raw Normal View History

1994-06-24 14:02:31 +00:00
#define RCSID5 "$Id$"
1987-02-26 19:46:35 +00:00
/*
1987-03-10 01:26:51 +00:00
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
1987-02-26 19:46:35 +00:00
*
*/
2019-03-24 16:12:21 +00:00
void op1(int mode)
{
1987-02-26 19:46:35 +00:00
int relpc = 0;
if (im1flag) {
if (mode == 067 || mode == 077) {
exp_1.val = adjust(exp_1);
relpc = RELPC;
}
#ifdef RELOCATION
RELOMOVE(relonami, rel_1);
if (rflag != 0 && PASS_RELO)
newrelo(exp_1.typ, RELO2|relpc);
#endif
emit2(exp_1.val);
im1flag = 0;
}
}
2019-03-24 16:12:21 +00:00
void op2(int mode)
{
1987-02-26 19:46:35 +00:00
int relpc = 0;
if (im2flag) {
if (mode == 067 || mode == 077) {
relpc = RELPC;
exp_2.val = adjust(exp_2);
}
#ifdef RELOCATION
RELOMOVE(relonami, rel_2);
if (rflag != 0 && PASS_RELO)
newrelo(exp_2.typ, RELO2|relpc);
#endif
emit2(exp_2.val);
im2flag = 0;
}
}
2019-03-24 16:12:21 +00:00
void branch(int opc,expr_t exp)
{
register int eval;
register int sm;
1987-02-26 19:46:35 +00:00
eval = adjust(exp) >> 1;
sm = fitb(eval);
if ((exp.typ & ~S_DOT) != DOTTYP && pass >= PASS_2) sm = 0;
if (!sm && pass >= PASS_2) {
serror("label too far");
}
emit2(opc | lowb(eval));
}
2019-03-24 16:12:21 +00:00
void ejump(int opc, expr_t exp)
{
register int sm,eval;
1987-02-26 19:46:35 +00:00
int gain;
# ifdef THREE_PASS
eval = adjust(exp) >> 1;
sm = fitb(eval);
if ((exp.typ & ~S_DOT) != DOTTYP) {
sm = 0;
}
gain = (opc == OPBRA ? 2 : 4);
if (small(sm,gain)) {
emit2( opc | lowb(eval));
}
else {
# endif
if (opc != OPBRA) {
1987-05-20 17:15:22 +00:00
emit2((opc^0400) | 02);
1987-02-26 19:46:35 +00:00
}
exp_1 = exp;
1987-02-26 19:46:35 +00:00
im1flag = 1;
1987-05-26 15:35:17 +00:00
emit2(0100|067);
op1(067);
1987-02-26 19:46:35 +00:00
# ifdef THREE_PASS
}
# endif
}
2019-03-24 16:12:21 +00:00
void sob(int reg, expr_t exp)
{
1987-02-26 19:46:35 +00:00
if ((exp.typ & ~S_DOT) != DOTTYP) {
serror("error in sob-label");
}
exp.val = ( - adjust(exp) ) >> 1;
fit(fit6(exp.val));
emit2( OPSOB | (reg << 6) | exp.val);
}
2019-03-24 16:12:21 +00:00
int jump(int opc,int opr)
{
register int val;
1987-02-26 19:46:35 +00:00
# ifdef THREE_PASS
1987-05-15 16:31:00 +00:00
if (opr==067) {
2019-03-24 16:12:21 +00:00
register int sm = 0;
1987-05-15 16:31:00 +00:00
1987-02-26 19:46:35 +00:00
val = adjust(exp_1) >> 1;
if ( fitb(val) && (exp_1.typ & ~S_DOT) == DOTTYP) {
sm = 1;
}
if (small(sm,2)) {
emit2(OPBRA | lowb(val));
im1flag = 0;
return(0);
}
}
1987-05-15 16:31:00 +00:00
# endif
1987-02-26 19:46:35 +00:00
emit2(opc | opr);
op1(opr);
2019-03-24 16:12:21 +00:00
return(0);
1987-02-26 19:46:35 +00:00
}
2019-03-24 16:12:21 +00:00
valu_t adjust(expr_t exp)
{
1987-02-26 19:46:35 +00:00
valu_t val;
val = exp.val - DOTVAL - 2;
# ifdef THREE_PASS
if (pass == PASS_2 && val > 0) val -= DOTGAIN;
# endif
return(val);
}