📄 simops.c
字号:
return 4;}/* sub reg1, reg2 */intOP_1A0 (){ unsigned int op0, op1, result, z, s, cy, ov; trace_input ("sub", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op1 - op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)); trace_output (OP_REG_REG); return 2;}/* subr reg1, reg2 */intOP_180 (){ unsigned int op0, op1, result, z, s, cy, ov; trace_input ("subr", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 - op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op0 < op1); ov = ((op0 & 0x80000000) != (op1 & 0x80000000) && (op0 & 0x80000000) != (result & 0x80000000)); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)); trace_output (OP_REG_REG); return 2;}/* sxh reg1 */intOP_E0 (){ trace_input ("mulh", OP_REG_REG, 0); State.regs[ OP[1] ] = (EXTEND16 (State.regs[ OP[1] ]) * EXTEND16 (State.regs[ OP[0] ])); trace_output (OP_REG_REG); return 2;}/* mulh sign_extend(imm5), reg2 */intOP_2E0 (){ trace_input ("mulh", OP_IMM_REG, 0); State.regs[ OP[1] ] = EXTEND16 (State.regs[ OP[1] ]) * SEXT5 (OP[0]); trace_output (OP_IMM_REG); return 2;}/* mulhi imm16, reg1, reg2 */intOP_6E0 (){ trace_input ("mulhi", OP_IMM16_REG_REG, 0); State.regs[ OP[1] ] = EXTEND16 (State.regs[ OP[0] ]) * EXTEND16 (OP[2]); trace_output (OP_IMM16_REG_REG); return 4;}/* cmp reg, reg */intOP_1E0 (){ unsigned int op0, op1, result, z, s, cy, ov; trace_input ("cmp", OP_REG_REG_CMP, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op1 - op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); /* Set condition codes. */ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)); trace_output (OP_REG_REG_CMP); return 2;}/* cmp sign_extend(imm5), reg */intOP_260 (){ unsigned int op0, op1, result, z, s, cy, ov; int temp; /* Compute the result. */ trace_input ("cmp", OP_IMM_REG_CMP, 0); temp = SEXT5 (OP[0]); op0 = temp; op1 = State.regs[OP[1]]; result = op1 - op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); /* Set condition codes. */ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)); trace_output (OP_IMM_REG_CMP); return 2;}/* setf cccc,reg2 */intOP_7E0 (){ trace_input ("setf", OP_EX1, 0); State.regs[ OP[1] ] = condition_met (OP[0]); trace_output (OP_EX1); return 4;}/* satadd reg,reg */intOP_C0 (){ unsigned int op0, op1, result, z, s, cy, ov, sat; trace_input ("satadd", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 + op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (result < op0 || result < op1); ov = ((op0 & 0x80000000) == (op1 & 0x80000000) && (op0 & 0x80000000) != (result & 0x80000000)); sat = ov; /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0) | (sat ? PSW_SAT : 0)); /* Handle saturated results. */ if (sat && s) State.regs[OP[1]] = 0x80000000; else if (sat) State.regs[OP[1]] = 0x7fffffff; trace_output (OP_REG_REG); return 2;}/* satadd sign_extend(imm5), reg */intOP_220 (){ unsigned int op0, op1, result, z, s, cy, ov, sat; int temp; trace_input ("satadd", OP_IMM_REG, 0); /* Compute the result. */ temp = SEXT5 (OP[0]); op0 = temp; op1 = State.regs[OP[1]]; result = op0 + op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (result < op0 || result < op1); ov = ((op0 & 0x80000000) == (op1 & 0x80000000) && (op0 & 0x80000000) != (result & 0x80000000)); sat = ov; /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0) | (sat ? PSW_SAT : 0)); /* Handle saturated results. */ if (sat && s) State.regs[OP[1]] = 0x80000000; else if (sat) State.regs[OP[1]] = 0x7fffffff; trace_output (OP_IMM_REG); return 2;}/* satsub reg1, reg2 */intOP_A0 (){ unsigned int op0, op1, result, z, s, cy, ov, sat; trace_input ("satsub", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op1 - op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); sat = ov; /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0) | (sat ? PSW_SAT : 0)); /* Handle saturated results. */ if (sat && s) State.regs[OP[1]] = 0x80000000; else if (sat) State.regs[OP[1]] = 0x7fffffff; trace_output (OP_REG_REG); return 2;}/* satsubi sign_extend(imm16), reg */intOP_660 (){ unsigned int op0, op1, result, z, s, cy, ov, sat; int temp; trace_input ("satsubi", OP_IMM_REG, 0); /* Compute the result. */ temp = EXTEND16 (OP[2]); op0 = temp; op1 = State.regs[ OP[0] ]; result = op1 - op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); sat = ov; /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0) | (sat ? PSW_SAT : 0)); /* Handle saturated results. */ if (sat && s) State.regs[OP[1]] = 0x80000000; else if (sat) State.regs[OP[1]] = 0x7fffffff; trace_output (OP_IMM_REG); return 4;}/* satsubr reg,reg */intOP_80 (){ unsigned int op0, op1, result, z, s, cy, ov, sat; trace_input ("satsubr", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 - op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (result < op0); ov = ((op1 & 0x80000000) != (op0 & 0x80000000) && (op1 & 0x80000000) != (result & 0x80000000)); sat = ov; /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0) | (sat ? PSW_SAT : 0)); /* Handle saturated results. */ if (sat && s) State.regs[OP[1]] = 0x80000000; else if (sat) State.regs[OP[1]] = 0x7fffffff; trace_output (OP_REG_REG); return 2;}/* tst reg,reg */intOP_160 (){ unsigned int op0, op1, result, z, s; trace_input ("tst", OP_REG_REG_CMP, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 & op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); /* Store the condition codes. */ PSW &= ~(PSW_Z | PSW_S | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)); trace_output (OP_REG_REG_CMP); return 2;}/* mov sign_extend(imm5), reg */intOP_200 (){ int value = SEXT5 (OP[0]); trace_input ("mov", OP_IMM_REG_MOVE, 0); State.regs[ OP[1] ] = value; trace_output (OP_IMM_REG_MOVE); return 2;}/* movhi imm16, reg, reg */intOP_640 (){ trace_input ("movhi", OP_UIMM16_REG_REG, 16); State.regs[ OP[1] ] = State.regs[ OP[0] ] + (OP[2] << 16); trace_output (OP_UIMM16_REG_REG); return 4;}/* sar zero_extend(imm5),reg1 */intOP_2A0 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("sar", OP_IMM_REG, 0); op0 = OP[0]; op1 = State.regs[ OP[1] ]; result = (signed)op1 >> op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (op0 - 1))); /* Store the result and condition codes. */ State.regs[ OP[1] ] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_IMM_REG); return 2;}/* sar reg1, reg2 */intOP_A007E0 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("sar", OP_REG_REG, 0); op0 = State.regs[ OP[0] ] & 0x1f; op1 = State.regs[ OP[1] ]; result = (signed)op1 >> op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (op0 - 1))); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_REG_REG); return 4;}/* shl zero_extend(imm5),reg1 */intOP_2C0 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("shl", OP_IMM_REG, 0); op0 = OP[0]; op1 = State.regs[ OP[1] ]; result = op1 << op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (32 - op0))); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_IMM_REG); return 2;}/* shl reg1, reg2 */intOP_C007E0 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("shl", OP_REG_REG, 0); op0 = State.regs[ OP[0] ] & 0x1f; op1 = State.regs[ OP[1] ]; result = op1 << op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (32 - op0))); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_REG_REG); return 4;}/* shr zero_extend(imm5),reg1 */intOP_280 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("shr", OP_IMM_REG, 0); op0 = OP[0]; op1 = State.regs[ OP[1] ]; result = op1 >> op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (op0 - 1))); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_IMM_REG); return 2;}/* shr reg1, reg2 */intOP_8007E0 (){ unsigned int op0, op1, result, z, s, cy; trace_input ("shr", OP_REG_REG, 0); op0 = State.regs[ OP[0] ] & 0x1f; op1 = State.regs[ OP[1] ]; result = op1 >> op0; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); cy = (op1 & (1 << (op0 - 1))); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0) | (cy ? PSW_CY : 0)); trace_output (OP_REG_REG); return 4;}/* or reg, reg */intOP_100 (){ unsigned int op0, op1, result, z, s; trace_input ("or", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 | op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)); trace_output (OP_REG_REG); return 2;}/* ori zero_extend(imm16), reg, reg */intOP_680 (){ unsigned int op0, op1, result, z, s; trace_input ("ori", OP_UIMM16_REG_REG, 0); op0 = OP[2]; op1 = State.regs[ OP[0] ]; result = op0 | op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)); trace_output (OP_UIMM16_REG_REG); return 4;}/* and reg, reg */intOP_140 (){ unsigned int op0, op1, result, z, s; trace_input ("and", OP_REG_REG, 0); /* Compute the result. */ op0 = State.regs[ OP[0] ]; op1 = State.regs[ OP[1] ]; result = op0 & op1; /* Compute the condition codes. */ z = (result == 0); s = (result & 0x80000000); /* Store the result and condition codes. */ State.regs[OP[1]] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV); PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)); trace_output (OP_REG_REG); return 2;}/* andi zero_extend(imm16), reg, reg */intOP_6C0 (){ unsigned int result, z; trace_input ("andi", OP_UIMM16_REG_REG, 0); result = OP[2] & State.regs[ OP[0] ]; /* Compute the condition codes. */ z = (result == 0); /* Store the result and condition codes. */ State.regs[ OP[1] ] = result; PSW &= ~(PSW_Z | PSW_S | PSW_OV); PSW |= (z ? PSW_Z : 0); trace_output (OP_UIMM16_REG_REG); return 4;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -