Skip to content

Commit 0d2405c

Browse files
committed
fix(instruction): EICALL is broken
close #59
1 parent 15fadca commit 0d2405c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/cpu/instruction.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ describe('avrInstruction', () => {
240240
avrInstruction(cpu);
241241
expect(cpu.pc).toEqual(0x11234);
242242
expect(cpu.cycles).toEqual(4);
243+
expect(cpu.data[SP]).toEqual(0x80 - 3); // according to datasheet: SP ← SP - 3
243244
expect(cpu.data[0x80]).toEqual(1); // Return address
244245
});
245246

src/cpu/instruction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ export function avrInstruction(cpu: ICPU) {
224224
const eind = cpu.data[0x3c];
225225
cpu.data[sp] = retAddr & 255;
226226
cpu.data[sp - 1] = (retAddr >> 8) & 255;
227-
cpu.dataView.setUint16(93, sp - 2, true);
227+
cpu.data[sp - 2] = (retAddr >> 16) & 255;
228+
cpu.dataView.setUint16(93, sp - 3, true);
228229
cpu.pc = ((eind << 16) | cpu.dataView.getUint16(30, true)) - 1;
229230
cpu.cycles += 3;
230231
} else if (opcode === 0x9419) {

0 commit comments

Comments
 (0)