aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils/assembler.spec.ts304
-rw-r--r--src/utils/assembler.ts127
2 files changed, 379 insertions, 52 deletions
diff --git a/src/utils/assembler.spec.ts b/src/utils/assembler.spec.ts
index 29453eb..614ff3d 100644
--- a/src/utils/assembler.spec.ts
+++ b/src/utils/assembler.spec.ts
@@ -46,4 +46,308 @@ describe('AVR assembler', () => {
lines: []
});
});
+
+ it('should correctly assemble `ADC r0, r1`', () => {
+ expect(assemble('ADC r0, r1').bytes).toEqual(bytes('011c'));
+ });
+
+ it('should correctly assemble `BCLR 2`', () => {
+ expect(assemble('BCLR 2').bytes).toEqual(bytes('a894'));
+ });
+
+ it('should correctly assemble `BLD r4, 7`', () => {
+ expect(assemble('BLD r4, 7').bytes).toEqual(bytes('47f8'));
+ });
+
+ it('should correctly assemble `BRBC 0, +8`', () => {
+ expect(assemble('BRBC 0, +8').bytes).toEqual(bytes('20f4'));
+ });
+
+ it('should correctly assemble `BRBS 3, 92`', () => {
+ expect(assemble('BRBS 3, 92').bytes).toEqual(bytes('73f1'));
+ });
+
+ it('should correctly assemble `BRBS 3, -4`', () => {
+ expect(assemble('BRBS 3, -4').bytes).toEqual(bytes('f3f3'));
+ });
+
+ it('should correctly assemble `CBI 0xc, 5`', () => {
+ expect(assemble('CBI 0xc, 5').bytes).toEqual(bytes('6598'));
+ });
+
+ it('should correctly assemble `CALL 0xb8`', () => {
+ expect(assemble('CALL 0xb8').bytes).toEqual(bytes('0e945c00'));
+ });
+
+ it('should correctly assemble `CPC r27, r18`', () => {
+ expect(assemble('CPC r27, r18').bytes).toEqual(bytes('b207'));
+ });
+
+ it('should correctly assemble `CPC r24, r1`', () => {
+ expect(assemble('CPC r24, r1').bytes).toEqual(bytes('8105'));
+ });
+
+ it('should correctly assemble `CPI r26, 0x9`', () => {
+ expect(assemble('CPI r26, 0x9').bytes).toEqual(bytes('a930'));
+ });
+
+ it('should correctly assemble `CPSE r2, r3`', () => {
+ expect(assemble('CPSE r2, r3`').bytes).toEqual(bytes('2310'));
+ });
+
+ it('should correctly assemble `ICALL`', () => {
+ expect(assemble('ICALL').bytes).toEqual(bytes('0995'));
+ });
+
+ it('should correctly assemble `IJMP`', () => {
+ expect(assemble('IJMP').bytes).toEqual(bytes('0994'));
+ });
+
+ it('should correctly assemble `IN r5, 0xb`', () => {
+ expect(assemble('IN r5, 0xb').bytes).toEqual(bytes('5bb0'));
+ });
+
+ it('should correctly assemble `INC r5`', () => {
+ expect(assemble('INC r5').bytes).toEqual(bytes('5394'));
+ });
+
+ it('should correctly assemble `JMP 0xb8`', () => {
+ expect(assemble('JMP 0xb8').bytes).toEqual(bytes('0c945c00'));
+ });
+
+ it('should correctly assemble `LAC r19`', () => {
+ expect(assemble('LAC Z, r19').bytes).toEqual(bytes('3693'));
+ });
+
+ it('should correctly assemble `LAS Z, r17`', () => {
+ expect(assemble('LAS Z, r17').bytes).toEqual(bytes('1593'));
+ });
+
+ it('should correctly assemble `LAT Z, r0`', () => {
+ expect(assemble('LAT Z, r0').bytes).toEqual(bytes('0792'));
+ });
+
+ it('should correctly assemble `LDI r28, 0xff`', () => {
+ expect(assemble('LDI r28, 0xff').bytes).toEqual(bytes('cfef'));
+ });
+
+ it('should correctly assemble `LDS r5, 0x150`', () => {
+ expect(assemble('LDS r5, 0x150').bytes).toEqual(bytes('50905001'));
+ });
+
+ it('should correctly assemble `LD r1, X`', () => {
+ expect(assemble('LD r1, X').bytes).toEqual(bytes('1c90'));
+ });
+
+ it('should correctly assemble `LD r17, X+`', () => {
+ expect(assemble('LD r17, X+').bytes).toEqual(bytes('1d91'));
+ });
+
+ it('should correctly assemble `LD r1, -X`', () => {
+ expect(assemble('LD r1, -X').bytes).toEqual(bytes('1e90'));
+ });
+
+ it('should correctly assemble `LD r8, Y`', () => {
+ expect(assemble('LD r8, Y').bytes).toEqual(bytes('8880'));
+ });
+
+ it('should correctly assemble `LD r3, Y+`', () => {
+ expect(assemble('LD r3, Y+').bytes).toEqual(bytes('3990'));
+ });
+
+ it('should correctly assemble `LD r0, -Y`', () => {
+ expect(assemble('LD r0, -Y').bytes).toEqual(bytes('0a90'));
+ });
+
+ it('should correctly assemble `LDD r4, Y+2`', () => {
+ expect(assemble('LDD r4, Y+2').bytes).toEqual(bytes('4a80'));
+ });
+
+ it('should correctly assemble `LD r5, Z`', () => {
+ expect(assemble('LD r5, Z').bytes).toEqual(bytes('5080'));
+ });
+
+ it('should correctly assemble `LD r7, Z+`', () => {
+ expect(assemble('LD r7, Z+').bytes).toEqual(bytes('7190'));
+ });
+
+ it('should correctly assemble `LD r0, -Z`', () => {
+ expect(assemble('LD r0, -Z').bytes).toEqual(bytes('0290'));
+ });
+
+ it('should correctly assemble `LDD r15, Z+31`', () => {
+ expect(assemble('LDD r15, Z+31').bytes).toEqual(bytes('f78c'));
+ });
+
+ it('should correctly assemble `LPM`', () => {
+ expect(assemble('LPM').bytes).toEqual(bytes('c895'));
+ });
+
+ it('should correctly assemble `LPM r2, Z`', () => {
+ expect(assemble('LPM r2, Z').bytes).toEqual(bytes('2490'));
+ });
+
+ it('should correctly assemble `LPM r1, Z+`', () => {
+ expect(assemble('LPM r1, Z+').bytes).toEqual(bytes('1590'));
+ });
+
+ it('should correctly assemble `LSR r7`', () => {
+ expect(assemble('LSR r7').bytes).toEqual(bytes('7694'));
+ });
+
+ it('should correctly assemble `MOV r7, r8`', () => {
+ expect(assemble('MOV r7, r8').bytes).toEqual(bytes('782c'));
+ });
+
+ it('should correctly assemble `MOVW r26, r22`', () => {
+ expect(assemble('MOVW r26, r22').bytes).toEqual(bytes('db01'));
+ });
+
+ it('should correctly assemble `MUL r5, r6`', () => {
+ expect(assemble('MUL r5, r6').bytes).toEqual(bytes('569c'));
+ });
+
+ it('should correctly assemble `MULS r18, r19`', () => {
+ expect(assemble('MULS r18, r19').bytes).toEqual(bytes('2302'));
+ });
+
+ it('should correctly assemble `MULSU r16, r17`', () => {
+ expect(assemble('MULSU r16, r17').bytes).toEqual(bytes('0103'));
+ });
+
+ it('should correctly assemble `NEG r20`', () => {
+ expect(assemble('NEG r20').bytes).toEqual(bytes('4195'));
+ });
+
+ it('should correctly assemble `NOP`', () => {
+ expect(assemble('NOP').bytes).toEqual(bytes('0000'));
+ });
+
+ it('should correctly assemble `OR r5, r2`', () => {
+ expect(assemble('OR r5, r2').bytes).toEqual(bytes('5228'));
+ });
+
+ it('should correctly assemble `ORI r22, 0x81`', () => {
+ expect(assemble('ORI r22, 0x81').bytes).toEqual(bytes('6168'));
+ });
+
+ it('should correctly assemble `OUT 0x3f, r1`', () => {
+ expect(assemble('OUT 0x3f, r1').bytes).toEqual(bytes('1fbe'));
+ });
+
+ it('should correctly assemble `POP r26`', () => {
+ expect(assemble('POP r26').bytes).toEqual(bytes('af91'));
+ });
+
+ it('should correctly assemble `PUSH r11`', () => {
+ expect(assemble('PUSH r11').bytes).toEqual(bytes('bf92'));
+ });
+
+ it('should correctly assemble `RCALL +6`', () => {
+ expect(assemble('RCALL +6').bytes).toEqual(bytes('03d0'));
+ });
+
+ it('should correctly assemble `RCALL -4`', () => {
+ expect(assemble('RCALL -4').bytes).toEqual(bytes('fedf'));
+ });
+
+ it('should correctly assemble `RET`', () => {
+ expect(assemble('RET').bytes).toEqual(bytes('0895'));
+ });
+
+ it('should correctly assemble `RETI`', () => {
+ expect(assemble('RETI').bytes).toEqual(bytes('1895'));
+ });
+
+ it('should correctly assemble `RJMP 2`', () => {
+ expect(assemble('RJMP 2').bytes).toEqual(bytes('01c0'));
+ });
+
+ it('should correctly assemble `ROR r0`', () => {
+ expect(assemble('ROR r0').bytes).toEqual(bytes('0794'));
+ });
+
+ it('should correctly assemble `SBCI r23, 3`', () => {
+ expect(assemble('SBCI r23, 3').bytes).toEqual(bytes('7340'));
+ });
+
+ it('should correctly assemble `SBI 0x0c, 5`', () => {
+ expect(assemble('SBI 0x0c, 5').bytes).toEqual(bytes('659a'));
+ });
+
+ it('should correctly assemble `SBIS 0x0c, 5`', () => {
+ expect(assemble('SBIS 0x0c, 5').bytes).toEqual(bytes('659b'));
+ });
+
+ it('should correctly assemble `SBIW r28, 2`', () => {
+ expect(assemble('SBIW r28, 2').bytes).toEqual(bytes('2297'));
+ });
+
+ it('should correctly assemble `SLEEP`', () => {
+ expect(assemble('SLEEP').bytes).toEqual(bytes('8895'));
+ });
+
+ it('should correctly assemble `SPM`', () => {
+ expect(assemble('SPM').bytes).toEqual(bytes('e895'));
+ });
+
+ it('should correctly assemble `SPM Z+`', () => {
+ expect(assemble('SPM Z+').bytes).toEqual(bytes('f895'));
+ });
+
+ it('should correctly assemble `STS 0x151, r31`', () => {
+ expect(assemble('STS 0x151, r31').bytes).toEqual(bytes('f0935101'));
+ });
+
+ it('should correctly assemble `ST X, r1`', () => {
+ expect(assemble('ST X, r1').bytes).toEqual(bytes('1c92'));
+ });
+
+ it('should correctly assemble `ST X+, r1`', () => {
+ expect(assemble('ST X+, r1').bytes).toEqual(bytes('1d92'));
+ });
+
+ it('should correctly assemble `ST -X, r17`', () => {
+ expect(assemble('ST -X, r17').bytes).toEqual(bytes('1e93'));
+ });
+
+ it('should correctly assemble `ST Y, r2`', () => {
+ expect(assemble('ST Y, r2').bytes).toEqual(bytes('2882'));
+ });
+
+ it('should correctly assemble `ST Y+, r1`', () => {
+ expect(assemble('ST Y+, r1').bytes).toEqual(bytes('1992'));
+ });
+
+ it('should correctly assemble `ST -Y, r1`', () => {
+ expect(assemble('ST -Y, r1').bytes).toEqual(bytes('1a92'));
+ });
+
+ it('should correctly assemble `STD Y+17, r0`', () => {
+ expect(assemble('STD Y+17, r0').bytes).toEqual(bytes('098a'));
+ });
+
+ it('should correctly assemble `ST Z, r16`', () => {
+ expect(assemble('ST Z, r16').bytes).toEqual(bytes('0083'));
+ });
+
+ it('should correctly assemble `ST Z+, r0`', () => {
+ expect(assemble('ST Z+, r0').bytes).toEqual(bytes('0192'));
+ });
+
+ it('should correctly assemble `ST -Z, r16`', () => {
+ expect(assemble('ST -Z, r16').bytes).toEqual(bytes('0293'));
+ });
+
+ it('should correctly assemble `STD Z+1, r0`', () => {
+ expect(assemble('STD Z+1, r0').bytes).toEqual(bytes('0182'));
+ });
+
+ it('should correctly assemble `SWAP r1`', () => {
+ expect(assemble('SWAP r1').bytes).toEqual(bytes('1294'));
+ });
+
+ it('should correctly assemble `XCH Z, r21`', () => {
+ expect(assemble('XCH Z, r21').bytes).toEqual(bytes('5493'));
+ });
});
diff --git a/src/utils/assembler.ts b/src/utils/assembler.ts
index a06063a..14fd61d 100644
--- a/src/utils/assembler.ts
+++ b/src/utils/assembler.ts
@@ -105,7 +105,7 @@ function constValue(r: string | number, min = 0, max = 255) {
*/
function fitTwoC(r: number, bits: number) {
if (bits < 2) {
- throw 'Need atleast 2 bits to be signed.';
+ throw 'Need at least 2 bits to be signed.';
}
if (bits > 16) {
throw 'fitTwoC only works on 16bit numbers for now.';
@@ -125,12 +125,11 @@ function fitTwoC(r: number, bits: number) {
* If offset is not 0, convert from absolute address to relative.
*/
function constOrLabel(c: string | number, labels: LabelTable, offset = 0) {
- if (typeof c == 'string') {
+ if (typeof c === 'string') {
let d = parseInt(c);
if (isNaN(d)) {
if (c in labels) {
d = labels[c] - offset;
- d = d >> 1; /* convert bytes into words. */
} else {
return NaN;
}
@@ -185,6 +184,9 @@ function stldXYZ(xyz: string) {
function stldYZq(yzq: string) {
const d = yzq.match(/([YZ])\+(\d+)/);
let r = 0x8000;
+ if (d == null) {
+ throw 'Invalid arguments';
+ }
switch (d[1]) {
case 'Y':
r |= 0x8;
@@ -196,7 +198,9 @@ function stldYZq(yzq: string) {
throw 'Not Y or Z with q';
}
const q = parseInt(d[2]);
- if (q < 0 || q > 64) throw 'q is out of range';
+ if (q < 0 || q > 64) {
+ throw 'q is out of range';
+ }
r |= ((q & 0x20) << 8) | ((q & 0x18) << 7) | (q & 0x7);
return r;
}
@@ -206,10 +210,9 @@ type opcodeHandler = (a: string, b: string, byteLoc: number, labels: LabelTable)
const SEflag = (a: number) => zeroPad(0x9408 | (constValue(a, 0, 7) << 4));
/**
- * Table of Mnemonics that can be assembled.
+ * Table of instructions that can be assembled.
*/
const OPTABLE: { [key: string]: opcodeHandler } = {
- /* Mnemonic: linecompiler */
ADD(a, b) {
const r = 0x0c00 | destRindex(a) | srcRindex(b);
return zeroPad(r);
@@ -221,7 +224,9 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
ADIW(a, b) {
let r = 0x9600;
const dm = a.match(/[Rr](24|26|28|30)/);
- if (!dm) throw 'Rd must be 24, 26, 28, or 30';
+ if (!dm) {
+ throw 'Rd must be 24, 26, 28, or 30';
+ }
let d = parseInt(dm[1]);
d = (d - 24) / 2;
r |= (d & 0x3) << 4;
@@ -259,7 +264,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return (l) => OPTABLE['BRBC']('a', b, byteLoc, l) as string;
}
let r = 0xf400 | constValue(a, 0, 7);
- r |= fitTwoC(constValue(k, -64, 63), 7) << 3;
+ r |= fitTwoC(constValue(k >> 1, -64, 63), 7) << 3;
return zeroPad(r);
},
BRBS(a, b, byteLoc, labels) {
@@ -268,7 +273,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return (l) => OPTABLE['BRBS']('a', b, byteLoc, l) as string;
}
let r = 0xf000 | constValue(a, 0, 7);
- r |= fitTwoC(constValue(k, -64, 63), 7) << 3;
+ r |= fitTwoC(constValue(k >> 1, -64, 63), 7) << 3;
return zeroPad(r);
},
BRCC(a, _, byteLoc, labels) {
@@ -344,7 +349,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return [(l) => OPTABLE['CALL'](a, b, byteLoc, l) as [string, string], 'xxxx'];
}
let r = 0x940e;
- k = constValue(k, 0, 0x400000);
+ k = constValue(k, 0, 0x400000) >> 1;
const lk = k & 0xffff;
const hk = (k >> 16) & 0x3f;
r |= ((hk & 0x3e) << 3) | (hk & 1);
@@ -422,7 +427,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return '9419';
},
ELPM(a, b) {
- if (typeof a == 'undefined' || a == '') {
+ if (typeof a === 'undefined' || a === '') {
return '95d8';
} else {
let r = 0x9000 | destRindex(a);
@@ -477,24 +482,30 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return [(l) => OPTABLE['JMP'](a, b, byteLoc, l) as [string, string], 'xxxx'];
}
let r = 0x940c;
- k = constValue(k, 0, 0x400000);
+ k = constValue(k, 0, 0x400000) >> 1;
const lk = k & 0xffff;
const hk = (k >> 16) & 0x3f;
r |= ((hk & 0x3e) << 3) | (hk & 1);
return [zeroPad(r), zeroPad(lk)];
},
LAC(a, b) {
- if (a != 'Z') throw 'First Operand is not Z';
+ if (a !== 'Z') {
+ throw 'First Operand is not Z';
+ }
const r = 0x9206 | destRindex(b);
return zeroPad(r);
},
LAS(a, b) {
- if (a != 'Z') throw 'First Operand is not Z';
+ if (a !== 'Z') {
+ throw 'First Operand is not Z';
+ }
const r = 0x9205 | destRindex(b);
return zeroPad(r);
},
LAT(a, b) {
- if (a != 'Z') throw 'First Operand is not Z';
+ if (a !== 'Z') {
+ throw 'First Operand is not Z';
+ }
const r = 0x9207 | destRindex(b);
return zeroPad(r);
},
@@ -518,7 +529,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return [zeroPad(r), zeroPad(k)];
},
LPM(a, b) {
- if (typeof a == 'undefined' || a == '') {
+ if (typeof a === 'undefined' || a === '') {
return '95c8';
} else {
let r = 0x9000 | destRindex(a);
@@ -599,7 +610,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
if (isNaN(k)) {
return (l) => OPTABLE['RCALL'](a, b, byteLoc, l) as string;
}
- const r = 0xd000 | fitTwoC(constValue(k, -2048, 2048), 12);
+ const r = 0xd000 | fitTwoC(constValue(k >> 1, -2048, 2047), 12);
return zeroPad(r);
},
RET() {
@@ -613,7 +624,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
if (isNaN(k)) {
return (l) => OPTABLE['RJMP'](a, b, byteLoc, l) as string;
}
- const r = 0xc000 | fitTwoC(constValue(k, -2048, 2048), 12);
+ const r = 0xc000 | fitTwoC(constValue(k >> 1, -2048, 2047), 12);
return zeroPad(r);
},
ROL(a, _, byteLoc, l) {
@@ -648,7 +659,9 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
SBIW(a, b) {
let r = 0x9700;
const dm = a.match(/[Rr](24|26|28|30)/);
- if (!dm) throw 'Rd must be 24, 26, 28, or 30';
+ if (!dm) {
+ throw 'Rd must be 24, 26, 28, or 30';
+ }
let d = parseInt(dm[1]);
d = (d - 24) / 2;
r |= (d & 0x3) << 4;
@@ -702,10 +715,12 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
return '9588';
},
SPM(a) {
- if (typeof a == 'undefined' || a == '') {
+ if (typeof a === 'undefined' || a === '') {
return '95e8';
} else {
- if (a != 'Z+') throw 'Bad param to SPM';
+ if (a !== 'Z+') {
+ throw 'Bad param to SPM';
+ }
return '95f8';
}
},
@@ -744,20 +759,22 @@ const OPTABLE: { [key: string]: opcodeHandler } = {
},
XCH(a, b) {
const r = 0x9204 | destRindex(b);
- if (a != 'Z') throw 'Bad param, not Z';
+ if (a !== 'Z') {
+ throw 'Bad param, not Z';
+ }
return zeroPad(r);
}
};
-function passone(inputdata: string) {
+function passOne(inputdata: string) {
const lines = inputdata.split('\n');
const commentReg = /[#;].*$/;
const labelReg = /^(\w+):/;
const codeReg = /^\s*(\w+)(?:\s+([^,]+)(?:,\s*(\S+))?)?\s*$/;
let lt: LineTablePass1;
- let res;
- let rets;
- let mnemonic;
+ let res: string;
+ let rets: RegExpMatchArray | null;
+ let instruction: string;
let byteOffset = 0;
const lableTable: LabelTable = {};
@@ -767,40 +784,46 @@ function passone(inputdata: string) {
for (let idx = 0; idx < lines.length; idx++) {
res = lines[idx].trim();
- if (res.length == 0) continue;
+ if (res.length === 0) {
+ continue;
+ }
lt = { line: idx + 1, text: res, bytes: [], byteOffset: 0 };
res = res.replace(commentReg, '').trim(); /* strip off comments. */
- if (res.length == 0) continue;
+ if (res.length === 0) {
+ continue;
+ }
/* check for a label */
rets = res.match(labelReg);
if (rets) {
lableTable[rets[1]] = byteOffset;
res = res.replace(labelReg, '').trim(); /* strip out label. */
}
- if (res.length == 0) continue;
+ if (res.length === 0) {
+ continue;
+ }
/* Check for a mnemonic line */
- res = res.match(codeReg);
+ const resMatch = res.match(codeReg);
try {
- if (res == null) {
+ if (resMatch === null) {
throw "doesn't match as code!";
}
- if (!res[1]) {
+ if (!resMatch[1]) {
throw 'Empty mnemonic field!';
}
/* do opcode */
- mnemonic = res[1].toUpperCase().trim();
+ instruction = resMatch[1].toUpperCase().trim();
/* This switch is ok for just these three.
* If ever to add more, then need to figure out how to merge all of the
* mnemonics into the OPTABLE. (or build a seperate internal op table)
*/
- switch (mnemonic) {
+ switch (instruction) {
case '_REPLACE':
- replacements[res[2]] = res[3];
+ replacements[resMatch[2]] = resMatch[3];
continue;
case '_LOC': {
- const num = parseInt(res[2]);
+ const num = parseInt(resMatch[2]);
if (isNaN(num)) {
throw 'Location is not a number.';
}
@@ -811,7 +834,7 @@ function passone(inputdata: string) {
continue;
}
case '_IW': {
- const num = parseInt(res[2]);
+ const num = parseInt(resMatch[2]);
if (isNaN(num)) {
throw 'Immeadiate Word is not a number.';
}
@@ -822,32 +845,32 @@ function passone(inputdata: string) {
}
}
- if (!(mnemonic in OPTABLE)) {
- throw 'No such mnemonic: ' + mnemonic;
+ if (!(instruction in OPTABLE)) {
+ throw 'No such instruction: ' + instruction;
}
/* do replacements on parameters. */
- if (res[2] in replacements) {
- res[2] = replacements[res[2]];
+ if (resMatch[2] in replacements) {
+ resMatch[2] = replacements[resMatch[2]];
}
- if (res[3] in replacements) {
- res[3] = replacements[res[3]];
+ if (resMatch[3] in replacements) {
+ resMatch[3] = replacements[resMatch[3]];
}
- rets = OPTABLE[mnemonic](res[2], res[3], byteOffset, lableTable);
+ const bytes = OPTABLE[instruction](resMatch[2], resMatch[3], byteOffset, lableTable);
lt.byteOffset = byteOffset;
- switch (typeof rets) {
+ switch (typeof bytes) {
case 'function':
case 'string':
byteOffset += 2;
break;
case 'object' /* assumed as an array. */:
- byteOffset += rets.length * 2;
+ byteOffset += bytes.length * 2;
break;
default:
throw 'unknown return type from optable.';
}
- lt.bytes = rets;
+ lt.bytes = bytes;
lineTable.push(lt);
} catch (err) {
errorTable.push('Line ' + idx + ': ' + err);
@@ -868,7 +891,7 @@ function elementSize(lt: LineTablePass1) {
/**
* Handle any forward referenced labels that were deferred in passone.
*/
-function passtwo(lineTable: LineTablePass1[], labels: LabelTable) {
+function passTwo(lineTable: LineTablePass1[], labels: LabelTable) {
const errorTable = [];
const lastElement = lineTable[lineTable.length - 1];
const byteSize = lastElement ? lastElement.byteOffset + elementSize(lastElement) : 0;
@@ -876,13 +899,13 @@ function passtwo(lineTable: LineTablePass1[], labels: LabelTable) {
for (const ltEntry of lineTable) {
try {
/* Look for functions left over from passone. */
- if (typeof ltEntry.bytes == 'function') {
+ if (typeof ltEntry.bytes === 'function') {
ltEntry.bytes = ltEntry.bytes(labels);
}
if (
ltEntry.bytes instanceof Array &&
ltEntry.bytes.length >= 1 &&
- typeof ltEntry.bytes[0] == 'function'
+ typeof ltEntry.bytes[0] === 'function'
) {
/* a bit gross. FIXME */
ltEntry.bytes = ltEntry.bytes[0](labels);
@@ -922,7 +945,7 @@ function passtwo(lineTable: LineTablePass1[], labels: LabelTable) {
* The assembler.
*/
export function assemble(input: string) {
- const mid = passone(input);
+ const mid = passOne(input);
if (mid.errors.length > 0) {
return {
bytes: new Uint8Array(0),
@@ -930,5 +953,5 @@ export function assemble(input: string) {
lines: []
};
}
- return passtwo(mid.lines, mid.labels);
+ return passTwo(mid.lines, mid.labels);
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.