68kcounter
Version:
68000 ASM source code cycle counter
68 lines (67 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const syntax_1 = require("../syntax");
const bitOps = [syntax_1.Mnemonics.BCHG, syntax_1.Mnemonics.BCLR, syntax_1.Mnemonics.BTST];
const branchOps = [
syntax_1.Mnemonics.BRA,
syntax_1.Mnemonics.BSR,
...syntax_1.mnemonicGroups.BCC,
];
const quick = [syntax_1.Mnemonics.MOVEQ, syntax_1.Mnemonics.ADDQ, syntax_1.Mnemonics.SUBQ];
const doubles = [
...syntax_1.mnemonicGroups.DBCC,
syntax_1.Mnemonics.LINK,
syntax_1.Mnemonics.MOVEM,
syntax_1.Mnemonics.MOVEP,
syntax_1.Mnemonics.STOP,
];
const dispTypes = [
syntax_1.AddressingModes.AnDisp,
syntax_1.AddressingModes.AnDispIx,
syntax_1.AddressingModes.PcDisp,
syntax_1.AddressingModes.PcDispIx,
];
/**
* Get byte size of instruction statement
*/
function instructionSize({ opcode: { op, qualifier }, operands, }) {
// Bcc.W is 2 words
if (branchOps.includes(op.name)) {
return qualifier && qualifier.name === syntax_1.Qualifiers.B ? 2 : 4;
}
// These instructions are always 2 words
if (doubles.includes(op.name)) {
return 4;
}
// Unary instructions are always 1 word
if (!operands.length) {
return 2;
}
let words = 1;
for (const { mode } of operands) {
// Absolute value:
if (mode === syntax_1.AddressingModes.AbsW) {
words += 1;
}
else if (mode === syntax_1.AddressingModes.AbsL) {
words += 2;
}
// Displacement
else if (dispTypes.includes(mode)) {
words += 1;
}
// Immediate value:
else if (mode === syntax_1.AddressingModes.Imm &&
!quick.includes(op.name) &&
!syntax_1.mnemonicGroups.SHIFT.includes(op.name)) {
if (bitOps.includes(op.name)) {
words += 1;
}
else {
words += qualifier && qualifier.name === syntax_1.Qualifiers.L ? 2 : 1;
}
}
}
return words * 2;
}
exports.default = instructionSize;