assembler - Add feature: allow use of `*` with a numeric offset

This commit is contained in:
n loewen 2023-08-24 15:26:37 +01:00
parent dc78518b73
commit d6b55db381
1 changed files with 14 additions and 2 deletions

View File

@ -53,6 +53,7 @@ const mnemonics2opcodes = {
* @property {SourceLineType} type - line type * @property {SourceLineType} type - line type
* @property {string} [operation] - For code: the first non-whitespace chunk * @property {string} [operation] - For code: the first non-whitespace chunk
* @property {string} [argument] - For code: the second non-whitespace chunk, if there is one * @property {string} [argument] - For code: the second non-whitespace chunk, if there is one
* @property {string} [extraArgument] - For code: the third non-whitespace chunk, if there is one
**/ **/
/** /**
@ -87,13 +88,20 @@ function preparseSourceCode(source) {
dbg(1, ``); dbg(1, ``);
if (info.type === 'code') { if (info.type === 'code') {
const op_arg_array = info.sanitized.split(/\s+/); // split line into an array of [op, arg] const op_arg_array = info.sanitized.split(/\s+/); // split line into an array of [op, arg, extra_arg]
if (op_arg_array[0] !== 'undefined') { if (op_arg_array[0] !== 'undefined') {
info.operation = op_arg_array[0]; info.operation = op_arg_array[0];
} }
if (op_arg_array.length === 2) { if (op_arg_array.length === 2) {
info.argument = op_arg_array[1]; info.argument = op_arg_array[1];
} }
if (op_arg_array.length === 3) {
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');
}
} }
return info; return info;
}); });
@ -285,7 +293,11 @@ function decodeInstructions(source) {
// Operands - Handle references to the Instruction Pointer // Operands - Handle references to the Instruction Pointer
if (line.argument === ASM_IP_LABEL) { if (line.argument === ASM_IP_LABEL) {
dbg(1, ` References current IP - ${IP}`); dbg(1, ` References current IP - ${IP}`);
if (typeof line.extraArgument === 'undefined') {
decodedArg = IP; decodedArg = IP;
} else {
decodedArg = IP + decodeNumericOp(line.extraArgument);
}
} }
// Operands - Handle references to constants // Operands - Handle references to constants