From 4e01a0943cc070b92a1305a215ed4fdb3b5a2607 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 21:29:28 +0100 Subject: [PATCH] Feature: Add `*ADDR` assembly operation (`*ADDR`, used as an operand, is replaced with the memory address where the current line will be stored after assembly) --- assembler.js | 8 ++++++++ notes/todo.md | 1 + readme.md | 3 +++ test-programs/referencing-addr-during-assembly.asm | 11 +++++++++++ 4 files changed, 23 insertions(+) create mode 100644 test-programs/referencing-addr-during-assembly.asm diff --git a/assembler.js b/assembler.js index 96a3893..aac84df 100644 --- a/assembler.js +++ b/assembler.js @@ -123,12 +123,19 @@ function decodeInstructions(line) { } dbg(2, `pointsToByte: ${labels[label].pointsToByte}`); dbg(2, `bytesToReplace: ${labels[label].bytesToReplace}`); + + // Handle references to the Instruction Pointer + } else if (arg_str.toLowerCase() === '*addr') { + dbg(2, `operand references current address`); + arg_num = IP; + dbg(2, `arg_num: ${num2hex(arg_num)}`); // Handle references to constants } else if (arg_str.startsWith('=')) { // FIXME - a quick hack to get around problems caused by another use of lower-casing to sanitize input: arg_str = arg_str.substring(1).toLowerCase(); // strip '>' dbg(2, `operand references '${arg_str}'`); + // TODO: support *ADDR arg_str = constants[arg_str]; dbg(2, `arg_str from '${arg_str}`); @@ -140,6 +147,7 @@ function decodeInstructions(line) { // FIXME - a quick hack to get around problems caused by another use of lower-casing to sanitize input: arg_str = arg_str.toLowerCase(); dbg(2, `INDY - operand references '${arg_str}'`); + // TODO: support *ADDR arg_str = constants[arg_str]; // Handle indirect expressions diff --git a/notes/todo.md b/notes/todo.md index 92fec6e..8637c4d 100644 --- a/notes/todo.md +++ b/notes/todo.md @@ -43,6 +43,7 @@ ### Assembler +- [ ] Support use of `*ADDR` with =constants - [ ] Pad up to 256 bytes - [ ] Validate labels - [ ] Return pure machine code when printing to stdout (and not in debug mode) diff --git a/readme.md b/readme.md index 20c9b12..81f49b2 100644 --- a/readme.md +++ b/readme.md @@ -93,5 +93,8 @@ With verbose debugging output: ADD =foo ; use a constant as an operand + LDA *ADDR ; `*ADDR` is a magic value referencing the memory address + ; that the current line will store at after assembly + - Hexadecimal numbers are preceded by a `$` - Whitespace is ignored \ No newline at end of file diff --git a/test-programs/referencing-addr-during-assembly.asm b/test-programs/referencing-addr-during-assembly.asm new file mode 100644 index 0000000..ed7031e --- /dev/null +++ b/test-programs/referencing-addr-during-assembly.asm @@ -0,0 +1,11 @@ +;; Test referencing address of line being assembled + +LDA *ADDR +STO $25 +FHP 0 ; hop if carry set + JMP @setCarry +END + +@setCarry + FTG 0 + JMP ($25) \ No newline at end of file