From 2d4cf8e169cfd7acf6dc09cf9bcc981a98db10e7 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Fri, 31 Jan 2020 13:44:36 +0200 Subject: fix(assembler): BRBC/BRBS forward labels fail --- src/utils/assembler.spec.ts | 8 ++++++++ src/utils/assembler.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/assembler.spec.ts b/src/utils/assembler.spec.ts index 614ff3d..7b1491f 100644 --- a/src/utils/assembler.spec.ts +++ b/src/utils/assembler.spec.ts @@ -71,6 +71,14 @@ describe('AVR assembler', () => { expect(assemble('BRBS 3, -4').bytes).toEqual(bytes('f3f3')); }); + it('should correctly assemble BREQ with forward label target', () => { + expect(assemble('BREQ next \n next:').bytes).toEqual(bytes('01f0')); + }); + + it('should correctly assemble BRNE with forward label target', () => { + expect(assemble('BRNE next \n next:').bytes).toEqual(bytes('01f4')); + }); + it('should correctly assemble `CBI 0xc, 5`', () => { expect(assemble('CBI 0xc, 5').bytes).toEqual(bytes('6598')); }); diff --git a/src/utils/assembler.ts b/src/utils/assembler.ts index 14fd61d..22ac948 100644 --- a/src/utils/assembler.ts +++ b/src/utils/assembler.ts @@ -261,7 +261,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = { BRBC(a, b, byteLoc, labels) { const k = constOrLabel(b, labels, byteLoc + 2); if (isNaN(k)) { - return (l) => OPTABLE['BRBC']('a', b, byteLoc, l) as string; + return (l) => OPTABLE['BRBC'](a, b, byteLoc, l) as string; } let r = 0xf400 | constValue(a, 0, 7); r |= fitTwoC(constValue(k >> 1, -64, 63), 7) << 3; @@ -270,7 +270,7 @@ const OPTABLE: { [key: string]: opcodeHandler } = { BRBS(a, b, byteLoc, labels) { const k = constOrLabel(b, labels, byteLoc + 2); if (isNaN(k)) { - return (l) => OPTABLE['BRBS']('a', b, byteLoc, l) as string; + return (l) => OPTABLE['BRBS'](a, b, byteLoc, l) as string; } let r = 0xf000 | constValue(a, 0, 7); r |= fitTwoC(constValue(k >> 1, -64, 63), 7) << 3; -- cgit v1.2.3