Make assembler a javascript module, remove code for working over stdio

This commit is contained in:
n loewen 2023-07-26 15:02:21 +01:00
parent 9797b2e25f
commit ba35470c3c
1 changed files with 3 additions and 12 deletions

View File

@ -1,5 +1,3 @@
// Usage: `node assembler_sketch.js assembly.asm`
// Syntax:
// ADD $01 ; comments follow a `;`
// ADD $FF ; this is direct addressing
@ -7,9 +5,6 @@
// END ; END, CFC, and CHP don't require arguments
// ; (a default value of 0 will be used as their operand)
const fs = require('fs');
const filename = process.argv[2];
const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp'];
const mnemonics2opcodes = {
end: { direct: 0, indirect: 0 },
@ -32,7 +27,7 @@ function decodeMultipleInstructions(str) {
output.push(decoded.op);
output.push(decoded.arg);
});
return output;
return new Uint8Array(output);
}
function decodeInstruction(line) {
@ -80,10 +75,6 @@ function hex2num(hex) { return parseInt(hex, 16) };
// RUN IT
try {
// console.log(`Reading ${filename}`);
const inputFile_str = fs.readFileSync(filename, 'utf8');
console.log(decodeMultipleInstructions(inputFile_str));
} catch (err) {
console.error(err);
exports.assemble = (str) => {
return decodeMultipleInstructions(str);
}