⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outco68.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
    PUTWORD(p, val);
    if (ins->oper1->mode != am_freg)
        putam(ins->length, ins, ins->oper1, p);
}

//-------------------------------------------------------------------------

int revmsk(int msk)
{
    int msk2 = 0;
    int i;
    for (i = 0; i < 16; i++)
    {
        msk2 <<= 1;
        if (msk &1)
            msk2 |= 1;
        msk >>= 1;
    }
    return msk2;
}

//-------------------------------------------------------------------------

int revmskf(int msk)
{
    int msk2 = 0;
    int i;
    for (i = 0; i < 8; i++)
    {
        msk2 <<= 1;
        if (msk &1)
            msk2 |= 1;
        msk >>= 1;
    }
    return msk2;
}

//-------------------------------------------------------------------------

int outcode_putop(OCODE *ins)
{
    int i, len;
    char *pos = ins->outbuf;
    char **p = &pos;
    switch (ins->opcode)
    {
        case op_abcd:
            putdecimal(0xc100, ins, p);
            break;
        case op_add:
            putmath(0xd000, ins, p);
            break;
        case op_adda:
            PUTWORD(p, 0xD0C0 + (ins->oper2->preg << 9) + ((ins->length == 4 ?
                1 : 0) << 8));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_addi:
            putmathimm(0x600, ins, p);
            break;
        case op_addq:
            PUTWORD(p, 0x5000 + ((ins->length / 2) << 6) + (((ins->oper1
                ->offset->v.i) &7) << 9));
            putam(ins->length, ins, ins->oper2, p);
            break;
        case op_addx:
            putaddx(0xd100, ins, p);
            break;
        case op_and:
            putmath(0xc000, ins, p);
            break;
        case op_andi:
            if (ins->oper2->mode == am_sr)
            {
                PUTWORD(p, 0x27c)PUTWORD(p, ins->oper1->offset->v.i);
            }
            else if (ins->oper2->mode == am_ccr)
            {
                PUTWORD(p, 0x23c)PUTWORD(p, ins->oper1->offset->v.i &255);
            }
            else
                putmathimm(0x200, ins, p);
            break;
        case op_asl:
            putshift(0xe100, ins, p);
            break;
        case op_asr:
            putshift(0xe000, ins, p);
            break;
        case op_bra:
            putbranch(0x6000, ins, p);
            break;
        case op_beq:
            putbranch(0x6700, ins, p);
            break;
        case op_bmi:
            putbranch(0x6b00, ins, p);
            break;
        case op_bpl:
            putbranch(0x6a00, ins, p);
            break;
        case op_bcc:
            putbranch(0x6400, ins, p);
            break;
        case op_bcs:
            putbranch(0x6500, ins, p);
            break;
        case op_bne:
            putbranch(0x6600, ins, p);
            break;
        case op_blt:
            putbranch(0x6d00, ins, p);
            break;
        case op_ble:
            putbranch(0x6f00, ins, p);
            break;
        case op_bgt:
            putbranch(0x6e00, ins, p);
            break;
        case op_bge:
            putbranch(0x6c00, ins, p);
            break;
        case op_bhi:
            putbranch(0x6200, ins, p);
            break;
        case op_bhs:
            putbranch(0x6400, ins, p);
            break;
        case op_blo:
            putbranch(0x6500, ins, p);
            break;
        case op_bls:
            putbranch(0x6300, ins, p);
            break;
        case op_bvc:
            putbranch(0x6800, ins, p);
            break;
        case op_bvs:
            putbranch(0x6900, ins, p);
            break;
        case op_bchg:
            putsbit(0x0140, 0x0840, ins, p);
            break;
        case op_bclr:
            putsbit(0x0180, 0x0880, ins, p);
            break;
        case op_bfclr:
            putfbit(0xecc0, ins, 0, ins->oper1, ins->oper2, p);
            break;
        case op_bfchg:
            putfbit(0xeac0, ins, 0, ins->oper1, ins->oper2, p);
            break;
        case op_bfexts:
            putfbit(0xebc0, ins, ins->oper3, ins->oper1, ins->oper2, p);
            break;
        case op_bfextu:
            putfbit(0xe9c0, ins, ins->oper3, ins->oper1, ins->oper2, p);
            break;
        case op_bfffo:
            putfbit(0xedc0, ins, ins->oper3, ins->oper1, ins->oper2, p);
            break;
        case op_bfins:
            putfbit(0xefc0, ins, ins->oper1, ins->oper2, ins->oper3, p);
            break;
        case op_bfset:
            putfbit(0xeec0, ins, 0, ins->oper1, ins->oper2, p);
            break;
        case op_bftst:
            putfbit(0xe8c0, ins, 0, ins->oper1, ins->oper2, p);
            break;
        case op_bkpt:
            PUTWORD(p, 0x4848 + ins->oper1->offset->v.i);
            break;
        case op_bset:
            putsbit(0x01c0, 0x08c0, ins, p);
            break;
        case op_bsr:
            putbranch(0x6100, ins, p);
            break;
        case op_btst:
            putsbit(0x0100, 0x0800, ins, p);
            break;
        case op_chk:
            PUTWORD(p, 0x4000 + (ins->oper2->preg << 9) + (ins->length == 2 ?
                0x180 : 0x100));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_chk2:
            PUTWORD(p, 0xc0 + (ins->length / 2 << 9));
            if (ins->oper2->mode == am_areg)
            {
                PUTWORD(p, 0x8800 + (ins->oper2->preg << 12));
            }
            else
                PUTWORD(p, 0x0800 + (ins->oper2->preg << 12));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_clr:
            PUTWORD(p, 0x4200 + (ins->length / 2 << 6));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_cmp:
            /* warning: DX expect as second operand */
            putmath(0xb000, ins, p);
            break;
        case op_cmpa:
            PUTWORD(p, 0xB0C0 + (ins->oper2->preg << 9) + ((ins->length == 4 ?
                1 : 0) << 8));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_cmpi:
            putmathimm(0xc00, ins, p);
            break;
        case op_cmpm:
            PUTWORD(p, 0xb108 + (ins->oper1->preg) + (ins->oper2->preg << 9) + 
                (ins->length / 2 << 6));
            break;
        case op_cmp2:
            PUTWORD(p, 0xc0 + ((ins->length / 2) << 9));
            PUTWORD(p, (ins->oper2->preg << 12) + (ins->oper2->mode == am_areg 
                ? 0x8000 : 0));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_dbra:
            putdbranch(0x5100, ins, p);
            break;
        case op_dbeq:
            putdbranch(0x5700, ins, p);
            break;
        case op_dbpl:
            putdbranch(0x5a00, ins, p);
            break;
        case op_dbmi:
            putdbranch(0x5b00, ins, p);
            break;
        case op_dbcc:
            putdbranch(0x5400, ins, p);
            break;
        case op_dbcs:
            putdbranch(0x5500, ins, p);
            break;
        case op_dbne:
            putdbranch(0x5600, ins, p);
            break;
        case op_dblt:
            putdbranch(0x5d00, ins, p);
            break;
        case op_dble:
            putdbranch(0x5f00, ins, p);
            break;
        case op_dbgt:
            putdbranch(0x5e00, ins, p);
            break;
        case op_dbge:
            putdbranch(0x5c00, ins, p);
            break;
        case op_dbhi:
            putdbranch(0x5200, ins, p);
            break;
        case op_dbhs:
            putdbranch(0x5400, ins, p);
            break;
        case op_dblo:
            putdbranch(0x5500, ins, p);
            break;
        case op_dbls:
            putdbranch(0x5300, ins, p);
            break;
        case op_dbvc:
            putdbranch(0x5800, ins, p);
            break;
        case op_dbvs:
            putdbranch(0x5900, ins, p);
            break;
        case op_divs:
            putmuldiv(0, 0x81c0, 0x4c40, 0x0800, ins, p);
            break;
        case op_divsl:
            putmuldiv(1, 0, 0x4c40, 0x0800, ins, p);
            break;
        case op_divu:
            putmuldiv(0, 0x80c0, 0x4c40, 0x0000, ins, p);
            break;
        case op_divul:
            putmuldiv(1, 0, 0x4c40, 0x0000, ins, p);
            break;
        case op_eor:
            /* Warning: Dx expected as first operand */
            PUTWORD(p, 0xb000 + 0x100 + (ins->oper1->preg << 9) + ((ins->length
                / 2) << 6));
            putam(ins->length, ins, ins->oper2, p);
            break;
        case op_eori:
            if (ins->oper2->mode == am_sr)
            {
                PUTWORD(p, 0xa7c)PUTWORD(p, ins->oper1->offset->v.i);
            }
            else if (ins->oper2->mode == am_ccr)
            {
                PUTWORD(p, 0xa3c)PUTWORD(p, ins->oper1->offset->v.i &255);
            }
            else
                putmathimm(0xa00, ins, p);
            break;
        case op_exg:
            {
                int val;
                AMODE *o1,  *o2;
                if (ins->oper1->mode == am_areg && ins->oper2->mode == am_dreg)
                {
                    o1 = ins->oper2;
                    o2 = ins->oper1;
                }
                else
                {
                    o1 = ins->oper1;
                    o2 = ins->oper2;
                }
                val = 0xC100 + (o1->preg << 9) + o2->preg;
                if (o2->mode == am_areg)
                    if (o1->mode == am_dreg)
                        val |= 0x88;
                    else
                        val |= 0x48;
                    else
                        val |= 0x40;
                PUTWORD(p, val);
            }
            break;
        case op_ext:
            PUTWORD(p, 0x4880 + (ins->length == 4 ? 0x40 : 0) + ins->oper1
                ->preg);
            break;
        case op_extb:
            PUTWORD(p, 0x49C0 + ins->oper1->preg);
            break;
        case op_illegal:
            PUTWORD(p, 0x4afc);
            break;
        case op_jmp:
            PUTWORD(p, 0x4EC0);
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_jsr:
            PUTWORD(p, 0x4E80);
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_lea:
            PUTWORD(p, 0x41C0 + (ins->oper2->preg << 9));
            putam(ins->length, ins, ins->oper1, p);
            break;
        case op_link:
            {
                int val = 0x4800;
                if (ins->length == 4)
                    val += 8;
                else
                    val += 0x650;
                PUTWORD(p, val + ins->oper1->preg);
                if (ins->length == 4)
                    PUTWORD(p, ins->oper2->offset->v.i >> 16);
                PUTWORD(p, ins->oper2->offset->v.i &65535);
            }
            break;
        case op_lsl:
            putshift(0xe108, ins, p);
            break;
        case op_lsr:
            putshift(0xe008, ins, p);
            break;


        case op_move:
            if (ins->oper1->mode == am_sr)
            {
                PUTWORD(p, 0x40c0);
                putam(ins->length, ins, ins->oper2, p);
                break;
            }
            else if (ins->oper1->mode == am_ccr)
            {
                PUTWORD(p, 0x42c0);
                putam(ins->length, ins, ins->oper2, p);
                break;
            }
            else if (ins->oper2->mode == am_sr)
            {
                PUTWORD(p, 0x46c0);
                putam(ins->length, ins, ins->oper1, p);
                break;
            }
            else if (ins->oper2->mode == am_ccr)
            {
                PUTWORD(p, 0x44c0);
                putam(ins->length, ins, ins->oper1, p);
                break;
            }
            // fall through
        case op_movea:
            switch (ins->length)
            {
            case 1:
                PUTWORD(p, 0x1000);
                break;
            case 2:
                PUTWORD(p, 0x3000);
                break;
            case 4:
            default:
                PUTWORD(p, 0x2000);
                break;
            }
            putam(ins->length, ins, ins->oper1, p);
            putam2(ins->length, ins, ins->oper2, p);
            break;
        case op_movem:
            if (ins->oper1->mode == am_mask)
            {
                PUTWORD(p, 0x4880 + (ins->length / 4 << 6));
                PUTWORD(p, revmsk((int)ins->oper1->offset));
                putam(ins->length, ins, ins->oper2, p);
            }
            else
            {
                PUTWORD(p, 0x4c80 + (ins->length / 4 << 6));
                PUTWORD(p, (int)ins->oper2->offset);
                putam(ins->length, ins, ins->oper1, p);
            }
            break;
        case op_movep:
            {
                int val;
                if (ins->oper1->mode == am_dreg)
                {
                    val = 0x188 + (ins->oper1->preg << 9);
                    if (ins->length == 4)
                        val |= 0x40;
                    val |= ins->oper2->preg;
                    PUTWORD(p, val);
                    PUTWORD(p, ins->oper2->offset->v.i);
                }
                else
                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -