Add .word directive

This commit is contained in:
2026-03-14 13:03:17 +00:00
parent 94cee7d258
commit cfa4fa7d4f

22
asm.js
View File

@@ -90,6 +90,7 @@ const State = Object.freeze({
AT_MEM: 18,
AT_ADDR: 19,
BYTE: 20,
WORD: 21,
});
const Action = Object.freeze({
@@ -149,6 +150,7 @@ class Parser {
".global": State.GLOBAL_NAME,
".at": State.AT_MEM,
".byte": State.BYTE,
".word": State.WORD,
};
this.handlers = {
[State.TOP]: (token) => this.token_top(token),
@@ -172,6 +174,7 @@ class Parser {
[State.AT_MEM]: (token) => this.token_at_mem(token),
[State.AT_ADDR]: (token) => this.token_at_addr(token),
[State.BYTE]: (token) => this.token_byte(token),
[State.WORD]: (token) => this.token_word(token),
};
this.results = [];
@@ -477,6 +480,25 @@ class Parser {
return action;
}
token_word(token) {
if (token == LINE_END) {
this.state = State.TOP;
return;
}
const action = { type: Action.DATA, size: 2 };
const value = this.integer(token);
if (value == null) {
console.error(
`ERROR: Unexpected token ${token}, expected value`);
return;
} else {
if (value > 0xffff)
console.error(`WARNING: Value ${token} is truncated`);
action.value = [ value & 0xff, (value >> 8) & 0xff ];
}
return action;
}
mem_action() {
const action = {
type: Action.MEM,