aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUri Shaked2020-01-31 13:44:36 +0200
committerUri Shaked2020-01-31 13:44:36 +0200
commit2d4cf8e169cfd7acf6dc09cf9bcc981a98db10e7 (patch)
tree96649e3e884d00c0ea1c5c25909cff4f344eb319
parentchore: github actions CI config (diff)
downloadavr8js-2d4cf8e169cfd7acf6dc09cf9bcc981a98db10e7.tar.gz
avr8js-2d4cf8e169cfd7acf6dc09cf9bcc981a98db10e7.tar.bz2
avr8js-2d4cf8e169cfd7acf6dc09cf9bcc981a98db10e7.zip
fix(assembler): BRBC/BRBS forward labels fail
-rw-r--r--src/utils/assembler.spec.ts8
-rw-r--r--src/utils/assembler.ts4
2 files changed, 10 insertions, 2 deletions
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;
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.