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

📄 outas386.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (prm_asmfile)
    if (gentype == longgen && outcol < 56)
    {
        #ifdef BCC32
            oprintf(outputFile, "\tDD\t0%lXH,0%lXH", val, val < 0 ?  - 1: 0);
        #else 
            oprintf(outputFile, "\tDD\t0%lXH,0%lXH", val, val >> 32);
        #endif 
        outcol += 10;
    }
    else
    {
        if (!newlabel)
            nl();
        else
            newlabel = FALSE;
        #ifdef BCC32
            oprintf(outputFile, "\tDD\t0%lXH,0%lXH", val, val < 0 ?  - 1: 0);
        #else 
            oprintf(outputFile, "\tDD\t0%lXH,0%lXH", val, val >> 32);
        #endif 
        gentype = longgen;
        outcol = 25;
    }
    else
        outcode_genlonglong(val);
}

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

void gensrref(SYM *sp, int val)
{
    char buf[512];
    if (prm_asmfile)
    {
        putsym(buf, sp, sp->name);
        if (gentype == srrefgen && outcol < 56)
        {
            oprintf(outputFile, ",%s,%d", buf, val);
            outcol += strlen(buf) + 1;
        }
        else
        {
            nl();
            oprintf(outputFile, "\tDD\t%s,%d", buf, val);
            gentype = srrefgen;
            outcol = 25;
        }
    }
    else
        outcode_gensrref(sp, val);
}

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

void genref(SYM *sp, int offset)
/*
 * Output a reference to the data area (also gens fixups )
 */
{
    char sign;
    char name[512], buf[512];
    if (prm_asmfile)
    {
        putsym(name, sp, sp->name);
        if (offset < 0)
        {
            sign = '-';
            offset =  - offset;
        }
        else
            sign = '+';
        sprintf(buf, "%s%c%d", name, sign, offset);
        if (prm_asmfile)
        {
            if (gentype == longgen && outcol < 55-strlen(buf))
            {
                oprintf(outputFile, ",%s", buf);
                outcol += (11+strlen(buf));
            }
            else
            {
                if (!newlabel)
                    nl();
                else
                    newlabel = FALSE;
                oprintf(outputFile, "\tDD\t%s", buf);
                outcol = 26+strlen(buf);
                gentype = longgen;
            }
        }
    }
    else
        outcode_genref(sp, offset);

}

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

void genpcref(SYM *sp, int offset)
/*
 * Output a reference to the code area (also gens fixups )
 */
{
    genref(sp, offset);
}

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

void genstorage(int nbytes)
/*
 * Output bytes of storage
 */
{
    if (prm_asmfile)
    {
        if (!newlabel)
            nl();
        else
            newlabel = FALSE;
        if (prm_nasm)
            oprintf(outputFile, "\tRESB\t0%XH", nbytes);
        else
            oprintf(outputFile, "\tDB\t0%XH DUP (?)", nbytes);
        outcol = 28;
        gentype = storagegen;
    }
    else
        outcode_genstorage(nbytes);
}

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

void gen_labref(int n)
/*
 * Generate a reference to a label
 */
{
    if (prm_asmfile)
    {
        if (gentype == longgen && outcol < 58)
        {
            oprintf(outputFile, ",L_%d", n);
            outcol += 6;
        }
        else
        {
            if (!newlabel)
                nl();
            else
                newlabel = FALSE;
            oprintf(outputFile, "\tDD\tL_%d", n);
            outcol = 22;
            gentype = longgen;
        }
    }
    else
        outcode_gen_labref(n);
}

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

void gen_labdifref(int n1, int n2)
{
    if (prm_asmfile)
    {
        if (gentype == longgen && outcol < 58)
        {
            oprintf(outputFile, ",L_%d-L_%d", n1, n2);
            outcol += 6;
        }
        else
        {
            if (!newlabel)
                nl();
            else
                newlabel = FALSE;
            oprintf(outputFile, "\tDD\tL_%d-L_%d", n1, n2);
            outcol = 22;
            gentype = longgen;
        }
    }
    else
        outcode_gen_labdifref(n1, n2);
}

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

int stringlit(char *s, int uselong, int len)
/*
 *      make s a string literal and return it's label number.
 */
{
    struct slit *lp = strtab;
    if (uselong)
        len *= 2;
    if (prm_optmult)
    {
        while (lp)
        {
            if (len == lp->len && !memcmp(lp->str, s, len))
                return lp->label;
            lp = lp->next;
        } 
    }
    ++global_flag; /* always allocate from global space. */
    lp = xalloc(sizeof(struct slit));
    lp->label = nextlabel++;
    lp->str = xalloc(len);
    memcpy(lp->str, s, len);
    lp->len = len;
    lp->next = strtab;
    lp->type = uselong;
    strtab = lp;
    --global_flag;
    return lp->label;
}

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

void dumplits(void)
/*
 *      dump the string literal pool.
 */
{
    if (prm_asmfile)
    {
        while (strtab != 0)
        {
            xstringseg();
            nl();
            put_label(strtab->label);
            genstring(strtab->str, strtab->type, strtab->len - 1);
            if (strtab->type)
                genword(0);
            else
                genbyte(0);
            strtab = strtab->next;
        } nl();
    }
    else
        outcode_dumplits();
}

/*
 * Exit if from a special segment
 */
void exitseg(void)
{
    if (prm_asmfile)
    {
        if (!prm_nasm)
        {
            if (curseg == startupxseg)
            {
                curseg = noseg;
                oprintf(outputFile, "cstartup\tENDS\n");
            }
            else if (curseg == rundownxseg)
            {
                curseg = noseg;
                oprintf(outputFile, "crundown\tENDS\n");
            }
            else if (curseg == cppxseg)
            {
                curseg = noseg;
                oprintf(outputFile, "cppinit\tENDS\n");
            }
            else if (curseg == constseg)
            {
                curseg = noseg;
                oprintf(outputFile, "_CONST\tENDS\n");
            }
            else if (curseg == stringseg)
            {
                curseg = noseg;
                oprintf(outputFile, "_STRING\tENDS\n");
            }
        }
    }
    else
        curseg = noseg;
}

/*
 * Switch to cseg 
 */
void cseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != codeseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION _TEXT\n");
                else
            {
                oprintf(outputFile, "SECTION .text\n");
                oprintf(outputFile, "[BITS 32]\n");
            }
            else
                oprintf(outputFile, "\t.CODE\n");
            curseg = codeseg;
        }
    }
    else
        curseg = codeseg;
}

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

void xconstseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != constseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION _CONST\n");
                else
                    cseg();
            }
            else
                oprintf(outputFile, 
                    "_CONST\tSEGMENT USE32 PUBLIC DWORD \042CONST\042\n");
            curseg = constseg;
        }
    }
    else
        curseg = constseg;
}

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

void xstringseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != stringseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION _STRING\n");
                else
                    dseg();
            }
            else
                oprintf(outputFile, 
                    "_STRING\tSEGMENT USE32 PUBLIC DWORD \042STRING\042\n");
            curseg = stringseg;
        }
    }
    else
        curseg = stringseg;
}

/*
 * Switch to deseg
 */
void dseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != dataseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION _DATA\n");
                else
                    oprintf(outputFile, "SECTION .data\n");
                else
                    oprintf(outputFile, "\t.DATA\n");
            curseg = dataseg;
        }
    }
    else
        curseg = dataseg;
}

/*
 * Switch to bssseg
 */
void bssseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != bssxseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION _BSS\n");
                else
                    oprintf(outputFile, "SECTION .bss\n");
                else
                    oprintf(outputFile, "\t.DATA?\n");
            curseg = bssxseg;
        }
    }
    else
        curseg = bssxseg;
}

/*
 * Switch to startupseg
 */
void startupseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != startupxseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION cstartup\n");
                else
                    dseg();
            }
            else
                oprintf(outputFile, 
                    "cstartup\tSEGMENT USE32 PUBLIC DWORD \042INITDATA\042\n");
            curseg = startupxseg;
        }
    }
    else
        curseg = startupxseg;
}

/*
 * Switch to rundownseg
 */
void rundownseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != rundownxseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION crundown\n");
                else
                    dseg();
            }
            else
                oprintf(outputFile, 
                    "crundown\tSEGMENT USE32 PUBLIC DWORD \042EXITDATA\042\n");
            curseg = rundownxseg;
        }
    }
    else
        curseg = rundownxseg;
}

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

void cppseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != cppxseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION cppinit\n");
                else
                    dseg();
            }
            else
                oprintf(outputFile, 
                    "cppinit\tSEGMENT USE32 PUBLIC DWORD \042CPPINIT\042\n");
            curseg = cppxseg;
        }
    }
    else
        curseg = cppxseg;
}

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

void cpprdseg(void)
{
    if (prm_asmfile)
    {
        if (curseg != cpprseg)
        {
            nl();
            exitseg();
            if (prm_nasm)
            {
                if (!prm_nodos)
                    oprintf(outputFile, "SECTION cppexit\n");
                else
                    dseg();
            }
            else
                oprintf(outputFile, 
                    "cpprundown\tSEGMENT USE32 PUBLIC DWORD \042CPPEXIT\042\n");
            curseg = cpprseg;
        }
    }
    else
        curseg = cpprseg;
}

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

    void gen_virtual(SYM *sp, int data)
    {
        if (!data && curseg != codeseg)
            cseg();
        virtual_mode = data;
        curseg = virtseg;
        if (prm_asmfile)
        {
            char buf[512];
            putsym(buf, sp, sp->name);
            nl();
            if (prm_nasm)
            {
                curseg = noseg;
                oprintf(outputFile, "\tSECTION @%s VIRTUAL\n", buf);
            }
            else
                oprintf(outputFile, "@%s\tSEGMENT VIRTUAL\n", buf);
            oprintf(outputFile, "%s:\n", buf);
        }
        else
            outcode_start_virtual_seg(sp, data);
    }
    void gen_endvirtual(SYM *sp)
    {
        if (prm_asmfile)
        {
            nl();
            if (!prm_nasm)
            {
                char buf[512];
                putsym(buf, sp, sp->name);
                oprintf(outputFile, "@%s\tENDS\n", buf);
            }
            else
                if (virtual_mode)
                    dseg();
                else
                    cseg();
        }
        else
            outcode_end_virtual_seg(sp);
        curseg = noseg;
    }
/*
 * Align
 */
void align(int size)
{
    if (curseg == codeseg)
        return ;
    if (prm_asmfile)
    {
        nl();
        if (prm_nasm)
        /* NASM 0.91 wouldn't let me use parenthesis but this should work
         * according to the documented precedence levels
         */
            oprintf(outputFile, "\tTIMES $$-$ & %d NOP\n", 3);
        else
            oprintf(outputFile, "\tALIGN\t%d\n", 4);
    }
    else
        outcode_align(size);
}

/*
 * queue muldiv val
 */
long queue_muldivval(long number)
{
    MULDIV *p = muldivlink, **q = &muldivlink;
    if (prm_optmult)
    {
        while (p)
        {
            if (p->size == 0 && p->value == number)
                return p->label;
            p = p->link;
        }
    }
    global_fl

⌨️ 快捷键说明

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