📄 asm.c
字号:
opword = 0xC1C0;
else /* MULU */
opword = 0xC0C0;
ea_mask = EA_DATA;
afun15b(ea_mask,opword,1);
break;
case 2:
opword = 0x4C00;
ea_mask = (DRD | ARI | ARIPO | ARIPR | ARID);
if (strcasecmp(instruct[0],"MULS") == 0)
opword2 = 0x0800;
Dn = get_data_register(instruct[2]);
if (!reg_error)
{
opword2 = (uint16)(opword2 | (Dn << 12));
opword2_flag = 1;
afun8(ea_mask,opword);
}
}
}
/****************************************************************/
void
afun13 (int ea_mask, uint16 opword)
{
/* TRAP #<vector> */
/* XXXXXXXXXXXXX|VEC| */
uint16 vector;
(void) ea_mask;
vector = (uint16)get_imm_data(instruct[1],0xfffffff0);
if (!error)
{
opword = (uint16)(opword | vector);
write_data(16,opword);
}
}
/****************************************************************/
void
afun14 (int ea_mask, uint16 opword)
{
/* LEA, ADDA, SUBA,*/
/* LEA <ea>,An */
/* XXXX|REG|XXXXXX|MOD|REG */
int An;
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]);
}
}
/****************************************************************/
void
afun15 (int ea_mask, uint16 opword)
{
/* CMP <ea>,Dn */
/* XXXX|REG|XXXXXX|MOD|REG */
int Dn;
#if (defined(CPU_MCF5407))
opword= 0xB000;
switch (size)
{
case 0:
/* byte */
break;
case 1:
opword = (uint16)(opword | (1 << 6));
break;
case 2:
opword = (uint16)(opword | (1 << 7));
ext_long_flag=1;
break;
default:
opword = (uint16)(opword | (1 << 7));
ext_long_flag=1;
break;
}
Dn = get_data_register(instruct[2]);
if (!reg_error)
{
opword = (uint16)(opword | (Dn << 9));
afun8(ea_mask,opword);
}
else
printf(ERR_DATA_REG,instruct[2]);
#else
if (size_is_long())
{
Dn = get_data_register(instruct[2]);
if (!reg_error)
{
ext_long_flag=1;
opword = (uint16)(opword | (Dn << 9));
afun8(ea_mask,opword);
}
else
printf(ERR_DATA_REG,instruct[2]);
}
#endif
}
/****************************************************************/
void
afun15b (int ea_mask, uint16 opword, int force_long)
{
int Dn, ea;
Dn = get_data_register(instruct[2]);
if (!reg_error)
{
opword = (uint16)(opword | (Dn << 9));
ea = get_ea(instruct[1],ea_mask,force_long);
if (!error)
{
opword = (uint16)(opword | ea);
write_data(16,opword);
handle_ext_words();
}
}
else
printf(ERR_DATA_REG,instruct[2]);
}
/****************************************************************/
void
afun16 (int ea_mask, uint16 opword)
{
/* ADDQ, SUBQ, #<data>,<ea> */
/* XXXX|DATa|XXX|MOD|REG */
uint16 data;
if (size_is_long())
{
data = (uint16)get_imm_data(instruct[1],0xfffffff0);
if (!error)
{
if (data == 8)
data = 0;
opword = (uint16)(opword | (data << 9));
afun8b(ea_mask,opword,0);
}
}
}
/****************************************************************/
void
afun17 (int ea_mask, uint16 opword)
{
/* EOR Dn,<ea> */
/* XXXX|REG|XXXXXX|MOD|REG */
int Dn;
if (size_is_long())
{
Dn = get_data_register(instruct[1]);
if (!reg_error)
{
opword = (uint16)(opword | (Dn << 9));
afun8b(ea_mask,opword,0);
}
else
printf(ERR_DATA_REG,instruct[2]);
}
}
/****************************************************************/
void
afun18 (int ea_mask, uint16 opword)
{
/* BRA, BSR, Bcc's */
/* Bxx <label> */
int32 disp;
uint32 label_addr;
(void) ea_mask;
if (symtab_convert_string(instruct[1],(ADDRESS *)&label_addr))
{
disp = label_addr - (asm_pc + 2); /* +2 from def. branch statements */
/* 32-bit,-2147483648 < disp < 2147483647 */
/* 16-bit, -32768 < disp < 32767 */
/* 8-bit, -128 < disp < 127 */
if (disp <= 127 && disp >= -128)
{
disp = disp & 0x00ff;
opword = (uint16)(opword | disp);
write_data(16,opword);
}
else if (((disp > 127) && (disp <= 32767)) || ((disp < -128) && (disp >= -32768)))
{
disp = disp & 0xffff;
ext_word = (int16)disp;
ext_word_flag = 1;
write_data(16,opword);
handle_ext_words();
}
#if (defined(CPU_MCF5407))
else if(((disp > 32767) && (disp <= 2147483647))
|| ((disp < -32768) && (disp >= (int32)-2147483648)))
{
ext_long = (int32)disp;
ext_long_flag = 1;
opword = (uint16)(opword | 0xFF);
write_data(16,opword);
handle_ext_words();
}
else
{
printf("Error: displacement larger that 32-bits\n");
return;
}
#else
else
{
printf("Error: displacement larger that 16-bits\n");
return;
}
#endif
}
else
printf("Not a valid label: %s\n",instruct[1]);
}
/****************************************************************/
void
afun19 (int ea_mask, uint16 opword)
{
/* MOVEQ */
/* MOVEQ #<data>,Dn */
uint16 data;
int Dn;
(void) ea_mask;
if (size_is_long())
{
data = (uint16)get_imm_data(instruct[1],0xFFFFFF00);
if (!error)
{
Dn = get_data_register(instruct[2]);
if (!reg_error)
{
opword = (uint16)(opword | (Dn << 9) | data);
write_data(16,opword);
}
else
printf(ERR_DATA_REG,instruct[2]);
}
}
}
/****************************************************************/
void
afun20 (int ea_mask, uint16 opword)
{
/* AND, OR, ADD, SUB */
/* AND Dn,<ea> */
/* AND <ea>,Dn */
int Dn;
/* ColdFire restricts these instructions to be size uint32 (ie: AND.L)
* But, if immediate addressing is used, get_ea() may only detect
* an extension word. To correct this, a variable 'force_long' is
* set when calling afun#(). 'afun8b(ea_mask,opword,force_long)'
*/
if (size_is_long())
{
if ((get_data_register(instruct[2])) != 8)
{
if ((strcasecmp(instruct[0],"AND") == 0) ||
(strcasecmp(instruct[0], "OR") == 0))
ea_mask = EA_DATA;
else
ea_mask = EA_ALL;
opword = (uint16)(opword | 0x80); /* <ea>,Dn */
afun15b(ea_mask, opword,1);
}
else
{
if ((Dn = get_data_register(instruct[1])) != 8)
{
opword = (uint16)(opword | 0x180 | (Dn << 9));
ea_mask = EA_MEMALT1;
afun8b(ea_mask,opword,0);
}
else
printf("Invalid operands: %s,%s\n",instruct[1],instruct[2]);
}
}
}
/****************************************************************/
void
afun21 (int ea_mask, uint16 opword)
{
/* WDEBUG <ea> */
opword2 = 0x0003;
opword2_flag = 1;
afun8(ea_mask,opword);
}
/****************************************************************/
void
afun22 (int ea_mask, uint16 opword)
{
/* ASL, ASR, LSL, LSR */
/* ASd Dx,Dy LSd Dx,Dy */
/* ASd #<data>,Dy LSd #<data>,Dy */
int count, Dy;
(void)ea_mask;
if (size_is_long())
{
if ((Dy = get_data_register(instruct[2])) != 8)
{
if ((count = get_data_register(instruct[1])) != 8)
{ /* Dx,Dy */
opword = (uint16)(opword | (count << 9) | 0x20 | Dy);
write_data(16,opword);
}
else
{ /* #<data>,Dy */
count = (uint16)get_imm_data(instruct[1],0xffffff0);
if (!error)
{
if (count == 0x8)
count = 0;
opword = (uint16)(opword | (count << 9) | Dy);
write_data(16,opword);
}
}
}
else
printf(ERR_DATA_REG,instruct[2]);
}
}
/****************************************************************/
void
afun23 (int ea_mask, uint16 opword)
{
/* ADDX, SUBX */
/* ADDX Dx,Dy */
int Dx, Dy;
(void)ea_mask;
if (size_is_long())
{
if ((Dx = get_data_register(instruct[1])) != 8)
{
if ((Dy = get_data_register(instruct[2])) != 8)
{
opword = (uint16)(opword | (Dy << 9) | Dx);
write_data(16,opword);
}
else
printf(ERR_DATA_REG,instruct[2]);
}
else
printf(ERR_DATA_REG,instruct[1]);
}
}
/****************************************************************/
static uint16
get_reg_list (char *user_list)
{
/* returns Register List Mask Field if a register list is present, */
/* success is FALSE if user_list is not a list of registers */
/* error is TRUE if list is of the wrong format */
/* list format: D0-D2/D4/D7/A1-A2/A7 etc. */
uint16 list = 0;
int i, j, Rn, Rt;
if (((get_data_register(user_list)) == 8) &&
((get_addr_register(user_list)) == 8))
{
success = FALSE;
return 0;
}
else
{
i = 0;
while(user_list[i] != NULL)
{
if ((Rn = get_data_register(&user_list[i])) != 8)
{ /* Rn = Rn + 0; */ }
else if ((Rn = get_addr_register(&user_list[i])) != 8)
Rn = Rn + 8;
else
{
user_list[i+2] = NULL;
printf("Invalid register entry: %s\n", &user_list[i]);
error = TRUE;
return 0;
}
list = (uint16)(list | (1 << Rn));
i += 2;
switch (user_list[i])
{
case '/':
i++;
break;
case '-':
i++;
if ((Rt = get_data_register(&user_list[i])) != 8)
{ /* Rt = Rt + 0; */ }
else if ((Rt = get_addr_register(&user_list[i])) != 8)
Rt = Rt + 8;
else
{
user_list[i+2] = NULL;
printf("Invalid register entry: %s\n", &user_list[i]);
error = TRUE;
return 0;
}
for (j = ++Rn; j <= Rt; j++)
{
list = (uint16)(list | (1 << j));
}
i+=2;
switch (user_list[i])
{
case '/':
i++;
break;
case NULL:
break;
default:
printf("Invalid list format: %s\n",user_list);
error = TRUE;
return 0;
}
break;
case NULL:
break;
default:
printf("Invalid list format: %s\n",user_list);
error = TRUE;
return 0;
}
}
return list;
}
}
/****************************************************************/
void
afun24 (int ea_mask, uint16 opword)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -