-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpuOpcodeIfTest.h
81 lines (68 loc) · 2.03 KB
/
cpuOpcodeIfTest.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef CPUOPCODEIFTEST_H
#define CPUOPCODEIFTEST_H
#include "common.h"
#include "dcpu.h"
TEST(cpu_opcode_if_test, IFE_A_B_will_only_run_the_next_instruction_if_A_and_B_are_equal)
{
const int arg1 = 0x0001;
const int arg2 = 0x0001;
int answer = 0x0002;
word memory[memorySize] = {0x040c, 0x0401 , 0x0011};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[PC] == answer-1);
reg[PC] = 0;
reg[B] = arg1+1;
cpu.execute();
ASSERT_TRUE(reg[PC] == answer);
}
TEST(cpu_opcode_if_test, IFN_A_B_will_only_run_the_next_instruction_if_A_and_B_are_not_equal)
{
//IFN A B
// SET X, Y
//SET Y, X
const int arg1 = 0x0001;
const int arg2 = 0x0000;
const int answer = 0x0002;
word memory[memorySize] = {0x040d, 0x0401 , 0x0011};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[PC] == answer-1);
reg[PC] = 0;
reg[A] = arg1-1; //make them equal
cpu.execute();
ASSERT_TRUE(reg[PC] == answer);
}
TEST(cpu_opcode_if_test, IFG_A_B_will_only_run_the_next_instruction_if_A_is_greater_than_B)
{
const int arg1 = 0x0001;
const int arg2 = 0x0000;
const int answer = 0x0002;
word memory[memorySize] = {0x040e, 0x0401 , 0x0011};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[PC] == answer-1);
reg[PC] = 0;
reg[A] = arg1-1;
cpu.execute();
ASSERT_TRUE(reg[PC] == answer);
}
TEST(cpu_opcode_if_test, IFB_A_B_will_only_run_the_next_instruction_if_A_and_B_is_not_equal_to_0) //correct?
{
const int arg1 = 0x00FF;
const int arg2 = 0x0FF0;
const int answer = 0x0002;
word memory[memorySize] = {0x040f, 0x0401 , 0x0011};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[PC] == answer-1);
reg[PC] = 0;
reg[B] = 0xFF00;
cpu.execute();
ASSERT_TRUE(reg[PC] == answer);
}
#endif // CPUOPCODEIFTEST_H