aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUri Shaked2020-04-02 13:09:44 +0300
committerUri Shaked2020-04-02 13:09:44 +0300
commitccba5deffd9ec13c9a7080610d606bf7274f3d4b (patch)
tree289349e16d8eb91ae2036bcd49bb3951a80aeb34 /src
parentfeat(demo): add LED labels (diff)
downloadavr8js-ccba5deffd9ec13c9a7080610d606bf7274f3d4b.tar.gz
avr8js-ccba5deffd9ec13c9a7080610d606bf7274f3d4b.tar.bz2
avr8js-ccba5deffd9ec13c9a7080610d606bf7274f3d4b.zip
test(instruction): use assembly in tests
Refactored the tests to use AVR assembly instead of hardcoded bytecode. This change should make the tests much easier to read and maintain. Before: loadProgram('659a'); Now: loadProgram('SBI 0x0c, 5');
Diffstat (limited to 'src')
-rw-r--r--src/cpu/instruction.spec.ts180
1 files changed, 91 insertions, 89 deletions
diff --git a/src/cpu/instruction.spec.ts b/src/cpu/instruction.spec.ts
index 2c5244e..c3508e6 100644
--- a/src/cpu/instruction.spec.ts
+++ b/src/cpu/instruction.spec.ts
@@ -1,5 +1,6 @@
import { CPU } from './cpu';
import { avrInstruction } from './instruction';
+import { assemble } from '../utils/assembler';
describe('avrInstruction', () => {
let cpu: CPU;
@@ -8,15 +9,16 @@ describe('avrInstruction', () => {
cpu = new CPU(new Uint16Array(0x8000));
});
- function loadProgram(bytes: string) {
- const progBuf = cpu.progBytes;
- for (let i = 0; i < bytes.length; i += 2) {
- progBuf[i / 2] = parseInt(bytes.substr(i, 2), 16);
+ function loadProgram(...instructions: string[]) {
+ const { bytes, errors } = assemble(instructions.join('\n'));
+ if (errors.length) {
+ throw new Error('Assembly failed: ' + errors);
}
+ cpu.progBytes.set(bytes, 0);
}
it('should execute `ADC r0, r1` instruction when carry is on', () => {
- loadProgram('011c');
+ loadProgram('ADC r0, r1');
cpu.data[0] = 10; // r0 <- 10
cpu.data[1] = 20; // r1 <- 20
cpu.data[95] = 0b00000001; // SREG <- -------C
@@ -28,7 +30,7 @@ describe('avrInstruction', () => {
});
it('should execute `ADC r0, r1` instruction when carry is on and the result overflows', () => {
- loadProgram('011c');
+ loadProgram('ADC r0, r1');
cpu.data[0] = 10; // r0 <- 10
cpu.data[1] = 245; // r1 <- 20
cpu.data[95] = 0b00000001; // SREG <- -------C
@@ -40,7 +42,7 @@ describe('avrInstruction', () => {
});
it('should execute `BCLR 2` instruction', () => {
- loadProgram('a894');
+ loadProgram('BCLR 2');
cpu.data[95] = 0xff; // SREG <- 0xff
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -49,7 +51,7 @@ describe('avrInstruction', () => {
});
it('should execute `BLD r4, 7` instruction', () => {
- loadProgram('47f8');
+ loadProgram('BLD r4, 7');
cpu.data[4] = 0x15; // r <- 0x15
cpu.data[95] = 0x40; // SREG <- 0x40
avrInstruction(cpu);
@@ -60,7 +62,7 @@ describe('avrInstruction', () => {
});
it('should execute `BRBC 0, +8` instruction when SREG.C is clear', () => {
- loadProgram('20f4');
+ loadProgram('BRBC 0, +8');
cpu.data[95] = 0b00001000; // SREG: V
avrInstruction(cpu);
expect(cpu.pc).toEqual(1 + 8 / 2);
@@ -68,7 +70,7 @@ describe('avrInstruction', () => {
});
it('should execute `BRBC 0, +8` instruction when SREG.C is set', () => {
- loadProgram('20f4');
+ loadProgram('BRBC 0, +8');
cpu.data[95] = 0b00000001; // SREG: C
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -76,7 +78,7 @@ describe('avrInstruction', () => {
});
it('should execute `BRBS 3, 92` instruction when SREG.V is set', () => {
- loadProgram('73f1');
+ loadProgram('BRBS 3, 92');
cpu.data[95] = 0b00001000; // SREG: V
avrInstruction(cpu);
expect(cpu.pc).toEqual(1 + 92 / 2);
@@ -84,7 +86,7 @@ describe('avrInstruction', () => {
});
it('should execute `BRBS 3, -4` instruction when SREG.V is set', () => {
- loadProgram('0000f3f3');
+ loadProgram('BRBS 3, -4');
cpu.data[95] = 0b00001000; // SREG: V
avrInstruction(cpu);
avrInstruction(cpu);
@@ -93,7 +95,7 @@ describe('avrInstruction', () => {
});
it('should execute `BRBS 3, -4` instruction when SREG.V is clear', () => {
- loadProgram('f3f3');
+ loadProgram('BRBS 3, -4');
cpu.data[95] = 0x0; // SREG <- 0x0
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -101,7 +103,7 @@ describe('avrInstruction', () => {
});
it('should execute `CBI 0x0c, 5`', () => {
- loadProgram('6598');
+ loadProgram('CBI 0x0c, 5');
cpu.data[0x2c] = 0b11111111;
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -110,7 +112,7 @@ describe('avrInstruction', () => {
});
it('should execute `CALL` instruction', () => {
- loadProgram('0e945c00');
+ loadProgram('CALL 0xb8');
cpu.data[94] = 0;
cpu.data[93] = 150; // SP <- 50
avrInstruction(cpu);
@@ -121,7 +123,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPC r27, r18` instruction', () => {
- loadProgram('b207');
+ loadProgram('CPC r27, r18');
cpu.data[18] = 0x1;
cpu.data[27] = 0x1;
avrInstruction(cpu);
@@ -131,7 +133,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPC r24, r1` instruction and set', () => {
- loadProgram('8105');
+ loadProgram('CPC r24, r1');
cpu.data[1] = 0; // r1 <- 0
cpu.data[24] = 0; // r24 <- 0
cpu.data[95] = 0b10000001; // SREG: I-------C
@@ -142,7 +144,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPI r26, 0x9` instruction', () => {
- loadProgram('a930');
+ loadProgram('CPI r26, 0x9');
cpu.data[26] = 0x8;
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -151,7 +153,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPSE r2, r3` when r2 != r3', () => {
- loadProgram('2310');
+ loadProgram('CPSE r2, r3');
cpu.data[2] = 10; // r2 <- 10
cpu.data[3] = 11; // r3 <- 11
avrInstruction(cpu);
@@ -160,7 +162,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPSE r2, r3` when r2 == r3', () => {
- loadProgram('23101c92');
+ loadProgram('CPSE r2, r3');
cpu.data[2] = 10; // r2 <- 10
cpu.data[3] = 10; // r3 <- 10
avrInstruction(cpu);
@@ -169,7 +171,7 @@ describe('avrInstruction', () => {
});
it('should execute `CPSE r2, r3` when r2 == r3 and followed by 2-word instruction', () => {
- loadProgram('23100e945c00');
+ loadProgram('CPSE r2, r3', 'CALL 8');
cpu.data[2] = 10; // r2 <- 10
cpu.data[3] = 10; // r3 <- 10
avrInstruction(cpu);
@@ -178,7 +180,7 @@ describe('avrInstruction', () => {
});
it('should execute `ICALL` instruction', () => {
- loadProgram('0995');
+ loadProgram('ICALL');
cpu.data[94] = 0;
cpu.data[93] = 0x80;
cpu.dataView.setUint16(30, 0x2020, true); // Z <- 0x2020
@@ -190,7 +192,7 @@ describe('avrInstruction', () => {
});
it('should execute `IJMP` instruction', () => {
- loadProgram('0994');
+ loadProgram('IJMP');
cpu.dataView.setUint16(30, 0x1040, true); // Z <- 0x1040
avrInstruction(cpu);
expect(cpu.cycles).toEqual(2);
@@ -198,7 +200,7 @@ describe('avrInstruction', () => {
});
it('should execute `IN r5, 0xb` instruction', () => {
- loadProgram('5bb0');
+ loadProgram('IN r5, 0xb');
cpu.data[0x2b] = 0xaf;
avrInstruction(cpu);
expect(cpu.cycles).toEqual(1);
@@ -207,7 +209,7 @@ describe('avrInstruction', () => {
});
it('should execute `INC r5` instruction', () => {
- loadProgram('5394');
+ loadProgram('INC r5');
cpu.data[5] = 0x7f;
avrInstruction(cpu);
expect(cpu.data[5]).toEqual(0x80);
@@ -217,7 +219,7 @@ describe('avrInstruction', () => {
});
it('should execute `INC r5` instruction when r5 == 0xff', () => {
- loadProgram('5394');
+ loadProgram('INC r5');
cpu.data[5] = 0xff;
avrInstruction(cpu);
expect(cpu.data[5]).toEqual(0);
@@ -227,14 +229,14 @@ describe('avrInstruction', () => {
});
it('should execute `JMP 0xb8` instruction', () => {
- loadProgram('0c945c00');
+ loadProgram('JMP 0xb8');
avrInstruction(cpu);
expect(cpu.pc).toEqual(0x5c);
expect(cpu.cycles).toEqual(3);
});
- it('should execute `LAC r19` instruction', () => {
- loadProgram('3693');
+ it('should execute `LAC Z, r19` instruction', () => {
+ loadProgram('LAC Z, r19');
cpu.data[19] = 0x02; // r19 <- 0x02
cpu.dataView.setUint16(30, 0x100, true); // Z <- 0x100
cpu.data[0x100] = 0x96;
@@ -246,8 +248,8 @@ describe('avrInstruction', () => {
expect(cpu.data[0x100]).toEqual(0x94);
});
- it('should execute `LAS r17` instruction', () => {
- loadProgram('1593');
+ it('should execute `LAS Z, r17` instruction', () => {
+ loadProgram('LAS Z, r17');
cpu.data[17] = 0x11; // r17 <- 0x11
cpu.data[30] = 0x80; // Z <- 0x80
cpu.data[0x80] = 0x44;
@@ -259,8 +261,8 @@ describe('avrInstruction', () => {
expect(cpu.data[0x80]).toEqual(0x55);
});
- it('should execute `LAT r0` instruction', () => {
- loadProgram('0792');
+ it('should execute `LAT Z, r0` instruction', () => {
+ loadProgram('LAT Z, r0');
cpu.data[0] = 0x33; // r0 <- 0x33
cpu.data[30] = 0x80; // Z <- 0x80
cpu.data[0x80] = 0x66;
@@ -273,7 +275,7 @@ describe('avrInstruction', () => {
});
it('should execute `LDI r28, 0xff` instruction', () => {
- loadProgram('cfef');
+ loadProgram('LDI r28, 0xff');
avrInstruction(cpu);
expect(cpu.pc).toEqual(0x1);
expect(cpu.cycles).toEqual(1);
@@ -281,7 +283,7 @@ describe('avrInstruction', () => {
});
it('should execute `LDS r5, 0x150` instruction', () => {
- loadProgram('50905001');
+ loadProgram('LDS r5, 0x150');
cpu.data[0x150] = 0x7a;
avrInstruction(cpu);
expect(cpu.pc).toEqual(0x2);
@@ -290,7 +292,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r1, X` instruction', () => {
- loadProgram('1c90');
+ loadProgram('LD r1, X');
cpu.data[0xc0] = 0x15;
cpu.data[26] = 0xc0; // X <- 0xc0
avrInstruction(cpu);
@@ -301,7 +303,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r17, X+` instruction', () => {
- loadProgram('1d91');
+ loadProgram('LD r17, X+');
cpu.data[0xc0] = 0x15;
cpu.data[26] = 0xc0; // X <- 0xc0
avrInstruction(cpu);
@@ -312,7 +314,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r1, -X` instruction', () => {
- loadProgram('1e90');
+ loadProgram('LD r1, -X');
cpu.data[0x98] = 0x22;
cpu.data[26] = 0x99; // X <- 0x99
avrInstruction(cpu);
@@ -323,7 +325,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r8, Y` instruction', () => {
- loadProgram('8880');
+ loadProgram('LD r8, Y');
cpu.data[0xc0] = 0x15;
cpu.data[28] = 0xc0; // Y <- 0xc0
avrInstruction(cpu);
@@ -334,7 +336,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r3, Y+` instruction', () => {
- loadProgram('3990');
+ loadProgram('LD r3, Y+');
cpu.data[0xc0] = 0x15;
cpu.data[28] = 0xc0; // Y <- 0xc0
avrInstruction(cpu);
@@ -345,7 +347,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r0, -Y` instruction', () => {
- loadProgram('0a90');
+ loadProgram('LD r0, -Y');
cpu.data[0x98] = 0x22;
cpu.data[28] = 0x99; // Y <- 0x99
avrInstruction(cpu);
@@ -356,7 +358,7 @@ describe('avrInstruction', () => {
});
it('should execute `LDD r4, Y+2` instruction', () => {
- loadProgram('4a80');
+ loadProgram('LDD r4, Y+2');
cpu.data[0x82] = 0x33;
cpu.data[28] = 0x80; // Y <- 0x80
avrInstruction(cpu);
@@ -367,7 +369,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r5, Z` instruction', () => {
- loadProgram('5080');
+ loadProgram('LD r5, Z');
cpu.data[0xcc] = 0xf5;
cpu.data[30] = 0xcc; // Z <- 0xcc
avrInstruction(cpu);
@@ -378,7 +380,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r7, Z+` instruction', () => {
- loadProgram('7190');
+ loadProgram('LD r7, Z+');
cpu.data[0xc0] = 0x25;
cpu.data[30] = 0xc0; // Z <- 0xc0
avrInstruction(cpu);
@@ -389,7 +391,7 @@ describe('avrInstruction', () => {
});
it('should execute `LD r0, -Z` instruction', () => {
- loadProgram('0290');
+ loadProgram('LD r0, -Z');
cpu.data[0x9e] = 0x66;
cpu.data[30] = 0x9f; // Z <- 0x9f
avrInstruction(cpu);
@@ -400,7 +402,7 @@ describe('avrInstruction', () => {
});
it('should execute `LDD r15, Z+31` instruction', () => {
- loadProgram('f78c');
+ loadProgram('LDD r15, Z+31');
cpu.data[0x9f] = 0x33;
cpu.data[30] = 0x80; // Z <- 0x80
avrInstruction(cpu);
@@ -411,7 +413,7 @@ describe('avrInstruction', () => {
});
it('should execute `LPM` instruction', () => {
- loadProgram('c895');
+ loadProgram('LPM');
cpu.progMem[0x40] = 0xa0;
cpu.data[30] = 0x80; // Z <- 0x80
avrInstruction(cpu);
@@ -421,8 +423,8 @@ describe('avrInstruction', () => {
expect(cpu.data[30]).toEqual(0x80); // verify that Z was unchanged
});
- it('should execute `LPM r2` instruction', () => {
- loadProgram('2490');
+ it('should execute `LPM r2, Z` instruction', () => {
+ loadProgram('LPM r2, Z');
cpu.progMem[0x40] = 0xa0;
cpu.data[30] = 0x80; // Z <- 0x80
avrInstruction(cpu);
@@ -433,7 +435,7 @@ describe('avrInstruction', () => {
});
it('should execute `LPM r1, Z+` instruction', () => {
- loadProgram('1590');
+ loadProgram('LPM r1, Z+');
cpu.progMem[0x40] = 0xa0;
cpu.data[30] = 0x80; // Z <- 0x80
avrInstruction(cpu);
@@ -444,7 +446,7 @@ describe('avrInstruction', () => {
});
it('should execute `LSR r7` instruction', () => {
- loadProgram('7694');
+ loadProgram('LSR r7');
cpu.data[7] = 0x45; // r7 <- 0x45
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -454,7 +456,7 @@ describe('avrInstruction', () => {
});
it('should execute `MOV r7, r8` instruction', () => {
- loadProgram('782c');
+ loadProgram('MOV r7, r8');
cpu.data[8] = 0x45; // r7 <- 0x45
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -463,7 +465,7 @@ describe('avrInstruction', () => {
});
it('should execute `MOVW r26, r22` instruction', () => {
- loadProgram('db01');
+ loadProgram('MOVW r26, r22');
cpu.data[22] = 0x45; // r22 <- 0x45
cpu.data[23] = 0x9a; // r23 <- 0x9a
avrInstruction(cpu);
@@ -474,7 +476,7 @@ describe('avrInstruction', () => {
});
it('should execute `MUL r5, r6` instruction', () => {
- loadProgram('569c');
+ loadProgram('MUL r5, r6');
cpu.data[5] = 100; // r5 <- 55
cpu.data[6] = 5; // r6 <- 5
avrInstruction(cpu);
@@ -485,7 +487,7 @@ describe('avrInstruction', () => {
});
it('should execute `MUL r5, r6` instruction and update carry flag when numbers are big', () => {
- loadProgram('569c');
+ loadProgram('MUL r5, r6');
cpu.data[5] = 200; // r5 <- 200
cpu.data[6] = 200; // r6 <- 200
avrInstruction(cpu);
@@ -496,7 +498,7 @@ describe('avrInstruction', () => {
});
it('should execute `MUL r0, r1` and update the zero flag', () => {
- loadProgram('019c');
+ loadProgram('MUL r0, r1');
cpu.data[0] = 0; // r0 <- 0
cpu.data[1] = 9; // r1 <- 9
avrInstruction(cpu);
@@ -507,7 +509,7 @@ describe('avrInstruction', () => {
});
it('should execute `MULS r18, r19` instruction', () => {
- loadProgram('2302');
+ loadProgram('MULS r18, r19');
cpu.data[18] = -5; // r18 <- -5
cpu.data[19] = 100; // r19 <- 100
avrInstruction(cpu);
@@ -518,7 +520,7 @@ describe('avrInstruction', () => {
});
it('should execute `MULSU r16, r17` instruction', () => {
- loadProgram('0103');
+ loadProgram('MULSU r16, r17');
cpu.data[16] = -5; // r16 <- -5
cpu.data[17] = 200; // r17 <- 200
avrInstruction(cpu);
@@ -529,7 +531,7 @@ describe('avrInstruction', () => {
});
it('should execute `NEG r20` instruction', () => {
- loadProgram('4195');
+ loadProgram('NEG r20');
cpu.data[20] = 0x56; // r20 <- 0x56
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -539,14 +541,14 @@ describe('avrInstruction', () => {
});
it('should execute `NOP` instruction', () => {
- loadProgram('0000');
+ loadProgram('NOP');
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
expect(cpu.cycles).toEqual(1);
});
it('should execute `OUT 0x3f, r1` instruction', () => {
- loadProgram('1fbe');
+ loadProgram('OUT 0x3f, r1');
cpu.data[1] = 0x5a; // r1 <- 0x5a
avrInstruction(cpu);
expect(cpu.pc).toEqual(0x1);
@@ -555,7 +557,7 @@ describe('avrInstruction', () => {
});
it('should execute `POP r26` instruction', () => {
- loadProgram('af91');
+ loadProgram('POP r26');
cpu.data[94] = 0;
cpu.data[93] = 0xff; // SP <- 0xff
cpu.data[0x100] = 0x1a;
@@ -567,7 +569,7 @@ describe('avrInstruction', () => {
});
it('should execute `PUSH r11` instruction', () => {
- loadProgram('bf92');
+ loadProgram('PUSH r11');
cpu.data[11] = 0x2a;
cpu.data[94] = 0;
cpu.data[93] = 0xff; // SP <- 0xff
@@ -579,7 +581,7 @@ describe('avrInstruction', () => {
});
it('should execute `RCALL .+6` instruction', () => {
- loadProgram('03d0');
+ loadProgram('RCALL 6');
cpu.data[94] = 0;
cpu.data[93] = 0x80; // SP <- 0x80
avrInstruction(cpu);
@@ -590,7 +592,7 @@ describe('avrInstruction', () => {
});
it('should execute `RCALL .-4` instruction', () => {
- loadProgram('0000fedf');
+ loadProgram('NOP', 'RCALL -4');
cpu.data[94] = 0;
cpu.data[93] = 0x80; // SP <- 0x80
avrInstruction(cpu);
@@ -602,7 +604,7 @@ describe('avrInstruction', () => {
});
it('should execute `RET` instruction', () => {
- loadProgram('0895');
+ loadProgram('RET');
cpu.data[94] = 0;
cpu.data[93] = 0x90; // SP <- 0x90
cpu.data[0x92] = 16;
@@ -613,7 +615,7 @@ describe('avrInstruction', () => {
});
it('should execute `RETI` instruction', () => {
- loadProgram('1895');
+ loadProgram('RETI');
cpu.data[94] = 0;
cpu.data[93] = 0xc0; // SP <- 0xc0
cpu.data[0xc2] = 200;
@@ -625,14 +627,14 @@ describe('avrInstruction', () => {
});
it('should execute `RJMP 2` instruction', () => {
- loadProgram('01c0');
+ loadProgram('RJMP 2');
avrInstruction(cpu);
expect(cpu.pc).toEqual(2);
expect(cpu.cycles).toEqual(2);
});
it('should execute `ROR r0` instruction', () => {
- loadProgram('0794');
+ loadProgram('ROR r0');
cpu.data[0] = 0x11; // r0 <- 0x11
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -642,7 +644,7 @@ describe('avrInstruction', () => {
});
it('should execute `SBCI r23, 3`', () => {
- loadProgram('7340');
+ loadProgram('SBCI r23, 3');
cpu.data[23] = 3; // r23 <- 3
cpu.data[95] = 0b10000001; // SREG <- I------C
avrInstruction(cpu);
@@ -652,7 +654,7 @@ describe('avrInstruction', () => {
});
it('should execute `SBI 0x0c, 5`', () => {
- loadProgram('659a');
+ loadProgram('SBI 0x0c, 5');
cpu.data[0x2c] = 0b00001111;
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -661,7 +663,7 @@ describe('avrInstruction', () => {
});
it('should execute `SBIS 0x0c, 5` when bit is clear', () => {
- loadProgram('659b1c92');
+ loadProgram('SBIS 0x0c, 5');
cpu.data[0x2c] = 0b00001111;
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -669,7 +671,7 @@ describe('avrInstruction', () => {
});
it('should execute `SBIS 0x0c, 5` when bit is set', () => {
- loadProgram('659b1c92');
+ loadProgram('SBIS 0x0c, 5');
cpu.data[0x2c] = 0b00101111;
avrInstruction(cpu);
expect(cpu.pc).toEqual(2);
@@ -677,7 +679,7 @@ describe('avrInstruction', () => {
});
it('should execute `SBIS 0x0c, 5` when bit is set and followed by 2-word instruction', () => {
- loadProgram('659b0e945c00');
+ loadProgram('SBIS 0x0c, 5', 'CALL 0xb8');
cpu.data[0x2c] = 0b00101111;
avrInstruction(cpu);
expect(cpu.pc).toEqual(3);
@@ -685,7 +687,7 @@ describe('avrInstruction', () => {
});
it('should execute `STS 0x151, r31` instruction', () => {
- loadProgram('f0935101');
+ loadProgram('STS 0x151, r31');
cpu.data[31] = 0x80; // r31 <- 0x80
avrInstruction(cpu);
expect(cpu.pc).toEqual(2);
@@ -694,7 +696,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST X, r1` instruction', () => {
- loadProgram('1c92');
+ loadProgram('ST X, r1');
cpu.data[1] = 0x5a; // r1 <- 0x5a
cpu.data[26] = 0x9a; // X <- 0x9a
avrInstruction(cpu);
@@ -705,7 +707,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST X+, r1` instruction', () => {
- loadProgram('1d92');
+ loadProgram('ST X+, r1');
cpu.data[1] = 0x5a; // r1 <- 0x5a
cpu.data[26] = 0x9a; // X <- 0x9a
avrInstruction(cpu);
@@ -716,7 +718,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST -X, r17` instruction', () => {
- loadProgram('1e93');
+ loadProgram('ST -X, r17');
cpu.data[17] = 0x88; // r17 <- 0x88
cpu.data[26] = 0x99; // X <- 0x99
avrInstruction(cpu);
@@ -727,7 +729,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST Y, r2` instruction', () => {
- loadProgram('2882');
+ loadProgram('ST Y, r2');
cpu.data[2] = 0x5b; // r2 <- 0x5b
cpu.data[28] = 0x9a; // Y <- 0x9a
avrInstruction(cpu);
@@ -738,7 +740,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST Y+, r1` instruction', () => {
- loadProgram('1992');
+ loadProgram('ST Y+, r1');
cpu.data[1] = 0x5a; // r1 <- 0x5a
cpu.data[28] = 0x9a; // Y <- 0x9a
avrInstruction(cpu);
@@ -749,7 +751,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST -Y, r1` instruction', () => {
- loadProgram('1a92');
+ loadProgram('ST -Y, r1');
cpu.data[1] = 0x5a; // r1 <- 0x5a
cpu.data[28] = 0x9a; // Y <- 0x9a
avrInstruction(cpu);
@@ -760,7 +762,7 @@ describe('avrInstruction', () => {
});
it('should execute `STD Y+17, r0` instruction', () => {
- loadProgram('098a');
+ loadProgram('STD Y+17, r0');
cpu.data[0] = 0xba; // r0 <- 0xba
cpu.data[28] = 0x9a; // Y <- 0x9a
avrInstruction(cpu);
@@ -771,7 +773,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST Z, r16` instruction', () => {
- loadProgram('0083');
+ loadProgram('ST Z, r16');
cpu.data[16] = 0xdf; // r2 <- 0xdf
cpu.data[30] = 0x40; // Z <- 0x40
avrInstruction(cpu);
@@ -782,7 +784,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST Z+, r0` instruction', () => {
- loadProgram('0192');
+ loadProgram('ST Z+, r0');
cpu.data[0] = 0x55; // r0 <- 0x55
cpu.dataView.setUint16(30, 0x155, true); // Z <- 0x155
avrInstruction(cpu);
@@ -793,7 +795,7 @@ describe('avrInstruction', () => {
});
it('should execute `ST -Z, r16` instruction', () => {
- loadProgram('0293');
+ loadProgram('ST -Z, r16');
cpu.data[16] = 0x5a; // r16 <- 0x5a
cpu.data[30] = 0xff; // Z <- 0xff
avrInstruction(cpu);
@@ -804,7 +806,7 @@ describe('avrInstruction', () => {
});
it('should execute `STD Z+1, r0` instruction', () => {
- loadProgram('0182');
+ loadProgram('STD Z+1, r0');
cpu.data[0] = 0xcc; // r0 <- 0xcc
cpu.data[30] = 0x50; // Z <- 0x50
avrInstruction(cpu);
@@ -815,7 +817,7 @@ describe('avrInstruction', () => {
});
it('should execute `SWAP r1` instruction', () => {
- loadProgram('1294');
+ loadProgram('SWAP r1');
cpu.data[1] = 0xa5; // r1 <- 0xa5
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
@@ -823,8 +825,8 @@ describe('avrInstruction', () => {
expect(cpu.data[1]).toEqual(0x5a); // r1
});
- it('should execute `XCH r21` instruction', () => {
- loadProgram('5493');
+ it('should execute `XCH Z, r21` instruction', () => {
+ loadProgram('XCH Z, r21');
cpu.data[21] = 0xa1; // r21 <- 0xa1
cpu.data[30] = 0x50; // Z <- 0x50
cpu.data[0x50] = 0xb9;
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.