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

📄 asm.c

📁 飞思卡尔的MC5271的写flash软件。
💻 C
📖 第 1 页 / 共 5 页
字号:
        {
            printf(ERR_OPER,instruct[3]);
            error=FALSE;
            return;
        }
    }
        
    /* handle instruct[4]*/

    for (i=1; instruct[4][i] != '&' && instruct[4][i] != NULL ; i++) /* Strip off the "&" if it is there */
    {}
    
    if(instruct[4][i]=='&')
    {
        instruct[4][i]=NULL;
        opword2  = (uint16)(opword2 | (0x1 <<5));
    }

    if(fiveoperands)                                                /* operand 4 must be an effective address */
    {
        ea=get_ea(instruct[4],ea_mask,0);

        if(!error)
            opword = (uint16)(opword | ea);                     /* instruction 3 is an effective address */
        else
        {
            printf(ERR_OPER,instruct[4]);
            error=FALSE;
            return;
        }
    }
    else
    {
        if ((reg=get_data_register(instruct[4]))==8)            /* Get Rw Destination field */
        {   
            if ((reg=get_addr_register(instruct[4])) != 8)      /* Rw could be an address register */
            {
                opword2  = (uint16)(opword2 | (reg << 12) | 0x8000 );       /* Rw IS an address register */
            }
            else                                                /* Rw is NOT a data or address register */
            {
                printf(ERR_OPER,instruct[4]);           
                return;
            }                                                   
        }
        else
        {
            opword2 = (uint16)(opword2 | (reg << 12));              /* Rw is a Data register */
        }
    }

/* handle instruct[5] IF !NULL */
    if(instruct[5] != NULL)
    {
        if ((reg=get_data_register(instruct[5]))==8)            /* Get Rw Destination field */
        {   
            if ((reg=get_addr_register(instruct[5])) != 8)      /* Rw could be an address register */
                opword2  = (uint16)(opword2 | (reg << 12) | 0x8000 );       /* Rw IS an address register */
        
            else                                                /* Rw is NOT a data or address register */
            {
                printf(ERR_OPER,instruct[5]);           
                return;
            }
        }
        else
            opword2 = (uint16)(opword2 | (reg << 12));              /* Rw is a Data register */
    }


    write_data(16,opword);
    handle_ext_words();

}
/****************************************************************/
void
afun30 (int ea_mask, uint16 opword)
{

    /* INTOUCH <Ay> */
    int reg;
    (void) ea_mask;

    if ((reg=get_addr_register(instruct[1])) != 8)      /* Ay could be an address register */
        opword  = (uint16)(opword  | reg);              /* Ay IS an address register */
    else
    {
        printf(ERR_ADDR_REG,instruct[1]);           
        return;
    }

    write_data(16,opword);
    handle_ext_words();


}
/****************************************************************/
void
afun31 (int ea_mask, uint16 opword)
{
    /* MOV3Q #<data>,<ea> */
    /* XXXX|DATa|XXX|MOD|REG        */
    uint16 data;
    
    data = (uint16)get_imm_data(instruct[1],0);
    if (!error)
    {
        if (data == 0xffff)
            data = 0;
        else if ((data > 7)||(data == 0 ))
        {
            printf(ERR_OPER,instruct[1]);
            return;
        }
        
        opword = (uint16)(opword | (data << 9));
        afun8b(ea_mask,opword,0);
        
    }
}
/****************************************************************/
void
afun32 (int ea_mask, uint16 opword)
{
    /* MVS <ea>y,Dx */
    /* MVZ <ea>y,Dx */
    /* XXXX|REG|XX|S|MOD|REG        */
    
    uint16 ea;
    int reg;
    
    switch (size)
    {
        case 0:
            /* byte-sized input operands */
            break;
        case 1:
            opword = (uint16)(opword | (1 << 6));           /* word-sized input operands */
            break;
        case 2:
            printf("Invalid size: .B or .W only\n");    /* NO long-sized input operands */
            return;
        default:
            /* default to byte-sized input operands */
            break;
    }

    ea=get_ea(instruct[1],ea_mask,0);
    
    if(!error)
        opword = (uint16)(opword | ea);                     
    else
    {
        printf(ERR_OPER,instruct[1]);
        error=FALSE;
        return;
    }
    
    if ((reg=get_data_register(instruct[2])) != 8)      
    opword  = (uint16)(opword  | (reg<<9));             
    else
    {
        printf(ERR_DATA_REG,instruct[2]);           
        return;
    }

    write_data(16,opword);
    handle_ext_words();


}
/****************************************************************/
void
afun33 (int ea_mask, uint16 opword)
{
    /* TAS */
    /* opword: XXXXXXXXXX|MOD|REG   */

    if((size==1)||(size==2))
    {
        printf("Invalid size: .B  only\n");         /*Byte-sized input operands only*/
        return;
    }
    else
        afun8(ea_mask,opword);

}   
/****************************************************************/
void
afun34 (int ea_mask, uint16 opword)
{
    /* CMPA <ea>,An         */
    /* XXXX|REG|XXXXXX|MOD|REG  */

    int An;

#if (defined(CPU_MCF5407))

    opword= 0xB000;
    switch (size)
    {
        case 0:
            /* byte */
            printf("Invalid size: .W and .L  only\n");
            return;
        case 1:
            opword = (uint16)(opword | (3 << 6));
            break;
        case 2:
            opword = (uint16)(opword | (7 << 6));
            ext_long_flag=1;
            break;
        default:
            opword = (uint16)(opword | (7 << 6));
            ext_long_flag=1;
            break;
    }
    
    An = get_addr_register(instruct[2]);
    if (!reg_error)
    {
        opword = (uint16)(opword | (An << 9));
        afun8(ea_mask,opword);
    }
    else
        printf(ERR_ADDR_REG,instruct[2]);

#else
    if (size_is_long())
    {
        An = get_addr_register(instruct[2]);
        if (!reg_error)
        {
            ext_long_flag=1;
            opword = (uint16)(opword | (An << 9));
            afun8(ea_mask,opword);
        }
        else
            printf(ERR_ADDR_REG,instruct[2]);
    }
#endif

}
/****************************************************************/
void 
afun35 (int ea_mask, uint16 opword)
{
    /* CMPI #<data>,Dn           */
#if (defined(CPU_MCF5407))

    opword= 0x0C00;
    switch (size)
    {
        case 0:
            /* byte */
            ext_word = (uint16)get_imm_data(instruct[1],0x0);
            ext_word_flag=1;
            break;
        case 1:
            opword = (uint16)(opword | (1 << 6));
            ext_word = (uint16)get_imm_data(instruct[1],0x0);
            ext_word_flag=1;
            break;
        case 2:
            opword = (uint16)(opword | (1 << 7));
            ext_long = get_imm_data(instruct[1],0x0);
            ext_long_flag=1;
            break;
        default:
            opword = (uint16)(opword | (1 << 7));
            ext_long = get_imm_data(instruct[1],0x0);
            ext_long_flag=1;
            break;
    }
    
    if (!error)
    {
        afun5(ea_mask,opword);
    }

#else
    if (size_is_long())
    {
        ext_long = get_imm_data(instruct[1],0x0);
        if (!error)
        {
            ext_long_flag = 1;
            afun5(ea_mask,opword);
        }
    }
#endif
}   
/****************************************************************/
#ifdef CPU_MCF_DIV 
void 
afun36 (int ea_mask, uint16 opword)
{
    /* DIVS.L DIVU.L DIVS.W DIVU.W*/
    int Dn;
        
    switch (size)
    {
        case 0:
            error = TRUE;
            printf("Invalid size specified:  .W or .L only\n");
            break;
        case 1:
            if (strcasecmp(instruct[0],"DIVS") == 0)
                opword = 0x81C0;
            else    /* DIVU */
                opword = 0x80C0;

            ea_mask = EA_DATA;
            afun15b(ea_mask,opword,0);
            break;
        case 2:
        default:
            opword = 0x4C40;
            ea_mask = (DRD | ARI | ARIPO | ARIPR | ARID);
            if (strcasecmp(instruct[0],"DIVS") == 0)
                opword2 = 0x0800;
            Dn = get_data_register(instruct[2]);
            if (!reg_error)
            {
                opword2 = (uint16)(opword2 | (Dn << 12) | Dn);
                opword2_flag = 1;
                afun8(ea_mask,opword);
            }
            break;
    }
}   
/****************************************************************/
void 
afun37 (int ea_mask, uint16 opword)
{
    /* REMS.L REMU.L*/
    int Dn,Dw, i;
    
    switch (size)
    {
        case 0:
            error = TRUE;
            printf("Invalid size specified:  .W or .L only\n");
            break;
        case 1:
            error = TRUE;
            printf("Invalid size specified:  .W or .L only\n");
            break;
        case 2:
        default:
            if (strcasecmp(instruct[0],"REMS") == 0)
                opword2 = 0x0800;
        
            for (i=0; (instruct[2][i] != ':') && (instruct[2][i] != NULL) ; i++)
            {}
            
            if (instruct[2][i] == ':') 
            {
                instruct[2][i] =NULL;
                instruct[3]=&instruct[2][i+1];  
            }
            else
            { 
                /* error there is no ":", no second register!*/
                printf(ERR_OPER,instruct[2]);
                return;
            }


            Dn = get_data_register(instruct[3]);
            if (!reg_error)
            {
                Dw = get_data_register(instruct[2]);
                if (!reg_error)
                {
                    opword2 = (uint16)(opword2 | (Dn << 12) | Dw);
                    opword2_flag = 1;
                    afun8(ea_mask,opword);
                }   
            }
            break;
    }
}
#endif /* CPU_MCF_DIV */
/****************************************************************/
static int 
check_equ(void)
{   
    /* 
     * Look for occurance of 'EQUATE' statement. 
     * If one is present, the symbol and value are stored 
     * in the symbol table and a '1' is returned.
     */
    int value, temp_base, i;

    if (instruct[1] == NULL)
        return 0;

    if ((strcasecmp(instruct[1],"equ") == 0) || 
       (instruct[1][0] == '.' && strcasecmp(&instruct[1][1],"equ") == 0))
    {
        if (instruct[2] != NULL)
        {
            check_base(instruct[2], &temp_base);
            value = get_value(instruct[2],&success,temp_base);
            if (success)
            {
                    for (i=1; instruct[0][i] != ':' && instruct[0][i] != NULL; i++)
                    {}
                if (instruct[0][i] == ':') 
                    instruct[0][i] = NULL;  
                symtab_add (instruct[0],value);
            }
            else
                printf(INVALUE,instruct[0]);
            return 1;  /* found 'equ', get new user_input */
        }
    }
    return 0;   /* no 'equ', user input is an instruction */        
}
/****************************************************************/
static void
sep_operands (void)
{   /* Fuction parses the operands in instruct[1] and stores the 
     * source operand in instruct[1] and the destination operand
     * in instruct[2] (if present). 
     */ 
    int i,j, parens = 0;

    for (j=1; (instruct[j] != NULL); j++)
    {

        for (i=0; ((instruct[j][i] != ',') || parens) && (instruct[j][i] != NULL); i++)
        {
            if (instruct[j][i] == '(')
                parens++;
            if (instruct[j][i] == ')')
                parens--;
        }

        if (instruct[j][i] == ',')
        {
            instruct[j][i] = NULL;
            instruct[j+1] = &instruct[j][i+1];
        }
        else
        instruct[j+1] = NULL;
    }

}   
/****************************************************************/
static void
che

⌨️ 快捷键说明

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