ack/mach/6805/as/mach5.c

57 lines
1.1 KiB
C
Raw Permalink Normal View History

1987-03-09 16:02:32 +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".
*/
1994-06-24 14:02:31 +00:00
#define RCSID5 "$Id$"
1986-12-05 16:58:29 +00:00
/*
* Motorola 6805 special routines
*/
/* VARARGS2 */
2019-03-24 16:10:32 +00:00
void branch(register int opc,expr_t exp,expr_t cell)
{
register int sm, dist;
1986-12-05 16:58:29 +00:00
int saving;
dist = exp.val - (DOTVAL + 2);
if((opc & 0xf0) == 0) dist -= 1; /* bitbranch */
if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
dist -= DOTGAIN;
sm = fitj(dist);
if ((exp.typ & ~S_DOT) != DOTTYP)
sm = 0;
if (opc == 0x20 || opc == 0xAD)
saving = 1;
else
saving = 3;
if (small(sm,saving)) {
emit1(opc);
if((opc & 0xF0) == 0) /* bit branch */
emit1(cell.val);
#ifdef RELOCATION
newrelo(exp.typ, RELPC|RELO1);
#endif
emit1(dist);
} else {
if (opc == 0xAD) /* bsr */
emit1(0xBD); /* jsr */
else {
if (opc != 0x20) { /* bra */
/* reverse condition : */
emit1(opc ^ 1);
if((opc & 0xF0) == 0) /* bitbranch */
emit1(cell.val);
emit1(3);
}
emit1(0xCC); /* jmp */
}
#ifdef RELOCATION
newrelo(exp.typ, RELPC|RELO2|RELBR);
#endif
emit2(exp.val);
}
}