! Refactor (assembler): Chance constant prefix from '=' to '#'

'=' could be confusing when referencing a constant, since it looks like assignment

'#' is hopefully clearer (by analog to #hashtags)

Breaking change!
This commit is contained in:
n loewen 2023-08-16 09:35:37 +01:00
parent 9fefa0916a
commit 3fd862a55d
4 changed files with 14 additions and 14 deletions

View File

@ -14,6 +14,7 @@ exports.assemble = (str, debug = false) => {
}
const POINTER_TO_CURRENT_ADDR_PSEUDO_OPERAND = '*addr';
const CONSTANT_PREFIX = '#';
const mnemonicsWithOptionalArgs = ['end', 'nop'];
const mnemonics2opcodes = {
@ -86,8 +87,7 @@ function decodeInstructions(line) {
let addressingMode = 'direct'; // Must be "direct" or "indirect"
// Handle constant definitions
if (opName.startsWith('=')) {
// TODO: validate constant
if (opName.startsWith(CONSTANT_PREFIX)) {
// FIXME - a quick hack to get around problems caused by another use of lower-casing to sanitize input:
let constantName = opName.substring(1).toLowerCase(); // strip '>'
let constantValue = arg_str;
@ -136,7 +136,7 @@ function decodeInstructions(line) {
dbg(2, `arg_num: ${num2hex(arg_num)}`);
// Handle references to constants
} else if (arg_str.startsWith('=')) {
} else if (arg_str.startsWith(CONSTANT_PREFIX)) {
// 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}'`);
@ -144,9 +144,9 @@ function decodeInstructions(line) {
dbg(2, `arg_str from '${arg_str}'`);
// Handle references to constants in indirect mode
} else if (arg_str.startsWith("(=")) {
} else if (arg_str.startsWith(`(${CONSTANT_PREFIX}`)) {
addressingMode = "indirect";
arg_str = arg_str.replace("(=", "");
arg_str = arg_str.replace(`(${CONSTANT_PREFIX}`, "");
arg_str = arg_str.replace(")", "");
// FIXME - a quick hack to get around problems caused by another use of lower-casing to sanitize input:
arg_str = arg_str.toLowerCase();

View File

@ -88,10 +88,10 @@ With verbose debugging output:
; the label will be replaced with
; the address of the label
=foo $FF ; define a constant
#foo $FF ; define a constant
; (must be defined before it is referenced)
ADD =foo ; use a constant as an operand
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

View File

@ -1,6 +1,6 @@
;; Test constants
=foo $01
=bar $02
ADD =foo
STO =bar
STO (=bar)
#foo $01
#bar $02
ADD #foo
STO #bar
STO (#bar)

View File

@ -1,13 +1,13 @@
;; Test referencing address of line being assembled
NOP ; Push the const below to a later address
=initAddr *ADDR
#initAddr *ADDR
LDA *ADDR
STO $25
FHP 0 ; hop if carry set
JMP @setCarry
LDA =initAddr
LDA #initAddr
END
@setCarry