-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2.h
More file actions
65 lines (52 loc) · 1.15 KB
/
code2.h
File metadata and controls
65 lines (52 loc) · 1.15 KB
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
#ifndef CODE2_H
#define CODE2_H
#include "stdint.h"
#include <iostream>
#include <cassert>
typedef enum {Z, S, C, V} Flag;
class Code2
{
int16_t *mem; //Buffer de memoria
bool flags[4];
int16_t registros[16];
uint16_t PC; //contador de programa
int16_t RI; //registro de instruccion
bool halt; //termino la ejecucion?
public:
Code2(uint16_t inic) {
PC = inic;
halt = false;
mem = new int16_t[65536];
}
~Code2() {
delete[]mem;
}
void set_mem(uint16_t pos, int16_t val) {
mem[pos] = val;
}
int16_t get_mem(uint16_t pos) {
return mem[pos];
}
bool termino_ejecucion() {
return halt;
}
int16_t get_reg(int r) {
return registros[r];
}
bool get_flag(Flag f) {
return flags[f];
}
void print_flags() {
std::cout << "flags: {Z = " << (flags[Z] ? 1:0)
<< "; C = " << (flags[C] ? 1:0)
<< "; S = " << (flags[S] ? 1:0)
<< "; V = " << (flags[V] ? 1:0) << "}" << std::endl;
}
void ejecutar_instruccion();
private:
void fetching() {
RI = mem[PC];
PC++;
}
};
#endif