Formatting: Rename 'argument' to 'operand' (except when it is shortened to 'arg', which is clearer)

This commit is contained in:
n loewen 2023-08-15 10:49:44 +01:00
parent 50741ba038
commit 3e753f6965
4 changed files with 33 additions and 34 deletions

View File

@ -94,7 +94,7 @@ function decodeInstructions(line) {
continue;
}
// Handle mnemonics without arguments (eg END) ...
// Handle mnemonics without operands (eg END) ...
if (typeof arg_str === 'undefined') {
if (mnemonicsWithOptionalArgs.indexOf(opName) < 0) {
console.error(`Missing opcode: ${line}`);
@ -103,7 +103,7 @@ function decodeInstructions(line) {
arg_num = 0;
// HANDLE ARGUMENTS
// HANDLE OPERANDS
// Handle references to labels
} else if (arg_str.startsWith('@')) {
@ -126,7 +126,7 @@ function decodeInstructions(line) {
// Handle references to constants
} else if (arg_str.startsWith('=')) {
arg_str = arg_str.substring(1) // strip '>'
dbg(2, `argument references '${arg_str}'`);
dbg(2, `operand references '${arg_str}'`);
arg_str = constants[arg_str];
dbg(2, `arg_str from '${arg_str}`);
@ -135,7 +135,7 @@ function decodeInstructions(line) {
addressingMode = "indirect";
arg_str = arg_str.replace("(=", "");
arg_str = arg_str.replace(")", "");
dbg(2, `INDY - argument references '${arg_str}'`);
dbg(2, `INDY - operand references '${arg_str}'`);
arg_str = constants[arg_str];
// Handle indirect expressions

View File

@ -12,21 +12,21 @@ const logMemory = (mem, start=0, end=mem.length) => {
if ((end % 2) === 1) { end += 1; }
mem = mem.slice(start, end);
console.log(`┌────────┬────────┬────────`);
console.log(`│ addr │ op │ arg `);
console.log(`├────────┼────────┼────────`);
console.log(`┌────────┬────────┬────────`);
console.log(`│ addr │ opcode │ operand`);
console.log(`├────────┼────────┼────────`);
//for (let i = 0; i < mem.length; i += 2) {
for (let i = start; i < mem.length; i +=2) {
console.log(`${num2hex(i)}${num2hex(mem[i])}${num2hex(mem[i+1])} `);
console.log(`${num2hex(i)}${num2hex(mem[i])}${num2hex(mem[i+1])} `);
// Add a blank row every 4 lines:
if (((i + 2) % 8) === 0) {
if ((i < (mem.length - 2))) {
console.log(`│ │ │ `);
console.log(`│ │ │ `);
}
}
}
console.log(`└────────┴────────┴────────`);
console.log(`└────────┴────────┴────────`);
}
const logRunningHeader = () => {

View File

@ -45,7 +45,7 @@ With verbose debugging output:
0F NOP ———— ; no operation
- Instructions are two bytes long:
one byte for the opcode, one for the argument
one byte for the opcode, one for the operand
## Registers and Flags
@ -66,20 +66,19 @@ With verbose debugging output:
## Assembly language
ADD $01 ; comments follow a `;`
ADD $FF ; this is direct addressing
ADD ($CC) ; this is indirect addressing
END ; END, CFC, and CHP don't require arguments
END ; END, CFC, and CHP don't require operands
; (a default value of 0 will be used as their operand)
@subroutine ; create a label
ADD $01 ; (it must be on the line before the code it names)
ADD $02
JMP @subroutine ; use a label as an argument
JMP @subroutine ; use a label as operand
; the label will be replaced with
; the address of the label

View File

@ -18,7 +18,7 @@ const CPU = {
currentInstruction: {
opcode: null,
argument: null,
operand: null,
mnemonic: null,
}
}
@ -158,22 +158,22 @@ const Instructions = {
}
const opcodes2mnemonics = {
0: (arg) => Instructions.end(),
1: (arg) => Instructions.store_lit(arg),
2: (arg) => Instructions.store_addr(arg),
3: (arg) => Instructions.load_lit(arg),
4: (arg) => Instructions.load_addr(arg),
5: (arg) => Instructions.add_lit(arg),
6: (arg) => Instructions.add_addr(arg),
7: (arg) => Instructions.sub_lit(arg),
8: (arg) => Instructions.sub_addr(arg),
9: (arg) => Instructions.hop_lit(arg),
10: (arg) => Instructions.hop_addr(arg),
11: (arg) => Instructions.jump_lit(arg),
12: (arg) => Instructions.jump_addr(arg),
13: (arg) => Instructions.carry_clear(),
14: (arg) => Instructions.carry_hop(),
15: (arg) => Instructions.no_op(),
0: (operand) => Instructions.end(),
1: (operand) => Instructions.store_lit(operand),
2: (operand) => Instructions.store_addr(operand),
3: (operand) => Instructions.load_lit(operand),
4: (operand) => Instructions.load_addr(operand),
5: (operand) => Instructions.add_lit(operand),
6: (operand) => Instructions.add_addr(operand),
7: (operand) => Instructions.sub_lit(operand),
8: (operand) => Instructions.sub_addr(operand),
9: (operand) => Instructions.hop_lit(operand),
10: (operand) => Instructions.hop_addr(operand),
11: (operand) => Instructions.jump_lit(operand),
12: (operand) => Instructions.jump_addr(operand),
13: (operand) => Instructions.carry_clear(),
14: (operand) => Instructions.carry_hop(),
15: (operand) => Instructions.no_op(),
};
/**
@ -190,9 +190,9 @@ function startCPU(code) {
**/
function stepCPU() {
CPU.currentInstruction.opcode = CPU.memory[CPU.IP];
CPU.currentInstruction.argument = CPU.memory[CPU.IP+1];
CPU.currentInstruction.operand = CPU.memory[CPU.IP+1];
let executeInstruction = opcodes2mnemonics[CPU.currentInstruction.opcode];
executeInstruction(CPU.currentInstruction.argument);
executeInstruction(CPU.currentInstruction.operand);
}
/**
@ -228,7 +228,7 @@ async function logCPUState(debug = false) {
}
console.log();
console.log('Mnemonic:', CPU.currentInstruction.mnemonic);
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.argument)}`);
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.operand)}`);
console.log();
console.log(`IP: $${num2hex(CPU.IP)} Acc: $${num2hex(CPU.Acc)} CF: ${CPU.CF}  ${CPU.running ? "running" : "halted" }`);
console.log();