diff --git a/asm.js b/asm.js index 6c5d0f8..0a902a2 100644 --- a/asm.js +++ b/asm.js @@ -578,7 +578,7 @@ class Parser { } else { if (value > 0xff) console.error(`WARNING: Value ${token} is truncated`); - action.value = [ value & 0xff ]; + action.value = value; } return action; } @@ -595,12 +595,7 @@ class Parser { } else { if (value > 0xffffffff) console.error(`WARNING: Value ${token} is truncated`); - action.value = [ - value & 0xff, - (value >> 8) & 0xff, - (value >> 16) & 0xff, - (value >> 24) & 0xff, - ]; + action.value = value; } return action; } @@ -614,8 +609,8 @@ class Parser { `ERROR: Unexpected token ${token}, expected string`); return; } - const value = this.encoder.encode(token.string); - const action = { type: Action.DATA, size: value.length, value }; + const bytes = this.encoder.encode(token.string); + const action = { type: Action.DATA, size: bytes.length, bytes }; return action; } @@ -1010,17 +1005,26 @@ export class Assembler { action_data(action) { const data = this.data.at(-1).data; - let value = action.value; - if (value == undefined) { - const raw = this.lookup_def(action.symbol); - if (raw == undefined) { - console.error( - `ERROR: Unable to resolve symbol ${action.symbol}`); - return; - } - value = this.le(raw, action.size); - } - data.push(...value); + let bytes; + if (action.bytes != undefined) { + bytes = action.bytes; + } else { + let value = action.value; + if (value == undefined) { + if (action.symbol == undefined) { + console.error("ERROR: Invalid data action", action); + return; + } + value = this.lookup_def(action.symbol); + if (value == undefined) { + console.error( + `ERROR: Unable to resolve symbol ${action.symbol}`); + return; + } + } + bytes = this.le(value, action.size); + } + data.push(...bytes); this.pos.addr += action.size; }