diff --git a/assembler.js b/assembler.js index ca998d2..1c5e0a7 100644 --- a/assembler.js +++ b/assembler.js @@ -99,8 +99,19 @@ function preparseSourceCode(source) { info.argument = op_arg_array[1]; info.extraArgument = op_arg_array[2]; } - if (op_arg_array.length > 3) { - console.error('Error on line ${info.number}: Too many arguments'); + // If there's too many arguments, throw an error + // NB. there's a special case: + // lines with the ASM_IP_LABEL can take an extra argument + let maxArgs = 2; + if (op_arg_array.length > 2 && op_arg_array[1].startsWith(ASM_IP_LABEL)) { + maxArgs = 3; + } + if (op_arg_array.length > maxArgs) { + console.error(); + console.error(`Error: Too many arguments`); + console.error(` at line ${info.number}`); + console.error(); + throw new Error("Too many arguments"); } } return info; @@ -226,7 +237,9 @@ function decodeInstructions(source) { // then it's an error if (!line.operation.startsWith('@')) { if (mnemonicsWithOptionalArgs.indexOf(line.operation.toLowerCase()) < 0) { - console.error(`Missing operand for line ${line.number}: ${line.source}`); + console.error(''); + console.error(`Error: Missing operand ${line.source}`); + console.error(` at line ${line.number}`); console.error(''); throw new Error("Missing operand"); } else {