MIXAL
machine_address_transfer.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "machine.h"
3 
9 namespace mixal {
10 
15 void Computer::executeINC(const InstructionWord& instruction, Register5* reg) {
16  int32_t value = reg->value();
17  int32_t address = getIndexedAddress(instruction);
18  value += address;
19  reg->set(checkRange(value));
20 }
21 
26 void Computer::executeDEC(const InstructionWord& instruction, Register5* reg) {
27  int32_t value = reg->value();
28  int32_t address = getIndexedAddress(instruction);
29  value -= address;
30  reg->set(checkRange(value));
31 }
32 
34 void Computer::executeENT(const InstructionWord& instruction, Register5* reg) {
35  int32_t address = getIndexedAddress(instruction);
36  reg->set(address);
37  if (address == 0) {
38  reg->negative = instruction.negative;
39  }
40 }
41 
43 void Computer::executeENN(const InstructionWord& instruction, Register5* reg) {
44  int32_t address = getIndexedAddress(instruction);
45  reg->set(-address);
46  if (address == 0) {
47  reg->negative = !instruction.negative;
48  }
49 }
50 
52 void Computer::executeINCi(const InstructionWord& instruction) {
53  int registerIndex = instruction.operation() - Instructions::INC1 + 1;
54  auto& rIi = rI(registerIndex);
55  int16_t value = rIi.value();
56  int16_t address = getIndexedAddress(instruction);
57  value += address;
58  rIi.set(checkRange(value, 2));
59 }
60 
62 void Computer::executeDECi(const InstructionWord& instruction) {
63  int registerIndex = instruction.operation() - Instructions::INC1 + 1;
64  auto& rIi = rI(registerIndex);
65  int16_t value = rIi.value();
66  int16_t address = getIndexedAddress(instruction);
67  value -= address;
68  rIi.set(checkRange(value, 2));
69 }
70 
72 void Computer::executeENTi(const InstructionWord& instruction) {
73  int registerIndex = instruction.operation() - Instructions::INC1 + 1;
74  auto& rIi = rI(registerIndex);
75  int16_t address = getIndexedAddress(instruction);
76  rIi.set(checkRange(address, 2));
77  if (address == 0) {
78  rIi.negative = instruction.negative;
79  }
80 }
81 
83 void Computer::executeENNi(const InstructionWord& instruction) {
84  int registerIndex = instruction.operation() - Instructions::INC1 + 1;
85  auto& rIi = rI(registerIndex);
86  int16_t address = getIndexedAddress(instruction);
87  rIi.set(checkRange(-address, 2));
88  if (address == 0) {
89  rIi.negative = !instruction.negative;
90  }
91 }
92 
93 }; // namespace mixal
machine.h
The virtual machine.
mixal::Computer::rI
Register2 & rI(int index)
Definition: machine.cpp:16