ack/mach/m65oo2/as/mach5.c

70 lines
1.1 KiB
C
Raw Permalink Normal View History

2024-02-22 15:13:52 +00:00
void
encode_imm(int opc, int sz, expr_t exp)
{
emit1(opc);
emit1(sz);
2024-02-23 15:09:37 +00:00
switch(TARGET_SIZE(sz))
2024-02-22 15:13:52 +00:00
{
case 0:
2024-02-23 15:09:37 +00:00
if (!FIT8(exp.val)) serror("bad operand size");
2024-02-22 15:13:52 +00:00
emit1(exp.val);
break;
2024-02-23 15:09:37 +00:00
2024-02-22 15:13:52 +00:00
case 1:
2024-02-23 15:09:37 +00:00
if (!FIT16(exp.val)) serror("bad operand size");
2024-02-22 15:13:52 +00:00
emit2(exp.val);
break;
2024-02-23 15:09:37 +00:00
case 2:
2024-02-22 15:13:52 +00:00
emit4(exp.val);
break;
2024-02-23 15:09:37 +00:00
default:
break;
}
}
void
encode_addr(expr_t exp, int sz)
{
uint32_t dist;
dist = exp.val;
if (FIT8(dist))
{
emit1(ADDR_SIZE_B | sz);
emit1(dist & 0xFF);
}
else if (FIT16(dist))
{
emit1(ADDR_SIZE_W | sz);
emit2(dist & 0xFFFF);
}
else
{
emit1(ADDR_SIZE_L | sz);
emit4(dist);
2024-02-22 15:13:52 +00:00
}
}
2024-02-22 19:37:12 +00:00
void branch(register int opc, expr_t exp)
2024-02-22 15:13:52 +00:00
{
2024-02-23 15:09:37 +00:00
uint32_t dist;
2024-02-22 15:13:52 +00:00
dist = exp.val - (DOTVAL + 2);
if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
dist -= DOTGAIN;
2024-02-23 15:09:37 +00:00
if (small(FIT16(dist) && (exp.typ & ~S_DOT) == DOTTYP, 3)) {
emit1(opc); emit2(dist & 0xFFFF);
2024-02-22 15:13:52 +00:00
} else {
2024-02-22 19:37:12 +00:00
emit1(opc^0x20); emit1(0x03); /* Skip over ... */
emit1(0x4C); /* ... far jump. */
2024-02-22 15:13:52 +00:00
#ifdef RELOCATION
2024-02-22 19:37:12 +00:00
newrelo(exp.typ, RELO2);
2024-02-22 15:13:52 +00:00
#endif
2024-02-22 19:37:12 +00:00
emit2(exp.val);
2024-02-22 15:13:52 +00:00
}
}