assembler - Add feature: allow use of `*` with a numeric offset
This commit is contained in:
parent
dc78518b73
commit
d6b55db381
16
assembler.js
16
assembler.js
|
|
@ -53,6 +53,7 @@ const mnemonics2opcodes = {
|
|||
* @property {SourceLineType} type - line type
|
||||
* @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} [extraArgument] - For code: the third non-whitespace chunk, if there is one
|
||||
**/
|
||||
|
||||
/**
|
||||
|
|
@ -87,13 +88,20 @@ function preparseSourceCode(source) {
|
|||
dbg(1, ``);
|
||||
|
||||
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') {
|
||||
info.operation = op_arg_array[0];
|
||||
}
|
||||
if (op_arg_array.length === 2) {
|
||||
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;
|
||||
});
|
||||
|
|
@ -285,7 +293,11 @@ function decodeInstructions(source) {
|
|||
// Operands - Handle references to the Instruction Pointer
|
||||
if (line.argument === ASM_IP_LABEL) {
|
||||
dbg(1, ` References current IP - ${IP}`);
|
||||
decodedArg = IP;
|
||||
if (typeof line.extraArgument === 'undefined') {
|
||||
decodedArg = IP;
|
||||
} else {
|
||||
decodedArg = IP + decodeNumericOp(line.extraArgument);
|
||||
}
|
||||
}
|
||||
|
||||
// Operands - Handle references to constants
|
||||
|
|
|
|||
Loading…
Reference in New Issue