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)

This commit is contained in:
n loewen 2023-08-15 21:29:28 +01:00
parent 5c41369ecd
commit 4e01a0943c
4 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)