1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
'use strict';
const { Core } = require('./core.js');
const { DAT, MOV } = require('./instruction.js');
const CORESIZE = 8000;
test('DAT does nothing and kills the program', () => {
const core = new Core(CORESIZE);
const pc = 0;
const ins = core.data[pc];
expect(DAT(core, pc, ins)).toEqual([]);
});
test('MOV correctly moves a full instruction', () => {
const core = new Core(CORESIZE);
const pc = 20;
core.data[pc] = {
opcode: 'MOV',
a: { mode: 'direct', value: 0 },
b: { mode: 'direct', value: 1 },
};
const ins = core.data[pc];
expect(core.data[pc+1].opcode).toBe('DAT');
expect(MOV(core, pc, ins)).toEqual([pc+1]);
expect(core.data[pc]).toEqual(core.data[pc+1]);
expect(core.data[pc+1].opcode).toBe('MOV');
});
test('MOV correctly moves a B-field', () => {
const core = new Core(CORESIZE);
const pc = 20;
core.data[pc] = {
opcode: 'MOV',
a: { mode: 'immediate', value: 100 },
b: { mode: 'direct', value: 1 },
};
const ins = core.data[pc];
expect(core.data[pc+1].opcode).toBe('DAT');
expect(MOV(core, pc, ins)).toEqual([pc+1]);
expect(core.data[pc+1]).toEqual({
opcode: 'DAT',
a: { mode: 'immediate', value: 0 },
b: { mode: 'immediate', value: 100 },
});
});
|