MIXAL
machine_jump.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "machine.h"
3 
9 namespace mixal {
10 
15 void Computer::executeJMP(const InstructionWord& instruction) {
16  int32_t address = getIndexedAddress(instruction, true);
17  rJ.set(_lineOffset + 1);
18  _lineOffset = address - 1;
19 }
20 
22 void Computer::executeJSJ(const InstructionWord& instruction) {
23  int32_t address = getIndexedAddress(instruction, true);
24  _lineOffset = address - 1;
25 }
26 
33 void Computer::executeJOV(const InstructionWord& instruction) {
34  if (overflow) {
35  this->executeJMP(instruction);
36  overflow = false;
37  }
38 }
39 
46 void Computer::executeJNOV(const InstructionWord& instruction) {
47  if (overflow) {
48  overflow = false;
49  } else {
50  this->executeJMP(instruction);
51  }
52 }
53 
58 void Computer::executeJL(const InstructionWord& instruction) {
59  if (comparison == ComparisonIndicator::LESS) {
60  this->executeJMP(instruction);
61  }
62 }
63 
68 void Computer::executeJE(const InstructionWord& instruction) {
69  if (comparison == ComparisonIndicator::EQUAL) {
70  this->executeJMP(instruction);
71  }
72 }
73 
78 void Computer::executeJG(const InstructionWord& instruction) {
79  if (comparison == ComparisonIndicator::GREATER) {
80  this->executeJMP(instruction);
81  }
82 }
83 
88 void Computer::executeJGE(const InstructionWord& instruction) {
89  if (comparison != ComparisonIndicator::LESS) {
90  this->executeJMP(instruction);
91  }
92 }
97 void Computer::executeJNE(const InstructionWord& instruction) {
98  if (comparison != ComparisonIndicator::EQUAL) {
99  int32_t address = getIndexedAddress(instruction, true);
100  rJ.set(_lineOffset + 1);
101  _lineOffset = address - 1;
102  }
103 }
104 
109 void Computer::executeJLE(const InstructionWord& instruction) {
110  if (comparison != ComparisonIndicator::GREATER) {
111  this->executeJMP(instruction);
112  }
113 }
114 
116 void Computer::executeJN(const InstructionWord& instruction, Register5* reg) {
117  if (reg->value() < 0) {
118  this->executeJMP(instruction);
119  }
120 }
121 
123 void Computer::executeJZ(const InstructionWord& instruction, Register5* reg) {
124  if (reg->value() == 0) {
125  this->executeJMP(instruction);
126  }
127 }
128 
130 void Computer::executeJP(const InstructionWord& instruction, Register5* reg) {
131  if (reg->value() > 0) {
132  this->executeJMP(instruction);
133  }
134 }
135 
137 void Computer::executeJNN(const InstructionWord& instruction, Register5* reg) {
138  if (reg->value() >= 0) {
139  this->executeJMP(instruction);
140  }
141 }
142 
144 void Computer::executeJNZ(const InstructionWord& instruction, Register5* reg) {
145  if (reg->value() != 0) {
146  this->executeJMP(instruction);
147  }
148 }
149 
151 void Computer::executeJNP(const InstructionWord& instruction, Register5* reg) {
152  if (reg->value() <= 0) {
153  this->executeJMP(instruction);
154  }
155 }
156 
158 void Computer::executeJiN(const InstructionWord& instruction) {
159  int registerIndex = instruction.operation() - Instructions::J1N + 1;
160  auto rIi = rI(registerIndex);
161  if (rIi.value() < 0) {
162  this->executeJMP(instruction);
163  }
164 }
165 
167 void Computer::executeJiZ(const InstructionWord& instruction) {
168  int registerIndex = instruction.operation() - Instructions::J1N + 1;
169  auto& rIi = rI(registerIndex);
170  if (rIi.value() == 0) {
171  this->executeJMP(instruction);
172  }
173 }
174 
176 void Computer::executeJiP(const InstructionWord& instruction) {
177  int registerIndex = instruction.operation() - Instructions::J1N + 1;
178  auto& rIi = rI(registerIndex);
179  if (rIi.value() > 0) {
180  this->executeJMP(instruction);
181  }
182 }
183 
185 void Computer::executeJiNN(const InstructionWord& instruction) {
186  int registerIndex = instruction.operation() - Instructions::J1N + 1;
187  auto& rIi = rI(registerIndex);
188  if (rIi.value() >= 0) {
189  this->executeJMP(instruction);
190  }
191 }
192 
194 void Computer::executeJiNZ(const InstructionWord& instruction) {
195  int registerIndex = instruction.operation() - Instructions::J1N + 1;
196  auto& rIi = rI(registerIndex);
197  if (rIi.value() != 0) {
198  this->executeJMP(instruction);
199  }
200 }
201 
203 void Computer::executeJiNP(const InstructionWord& instruction) {
204  int registerIndex = instruction.operation() - Instructions::J1N + 1;
205  auto& rIi = rI(registerIndex);
206  if (rIi.value() <= 0) {
207  this->executeJMP(instruction);
208  }
209 }
210 
211 }; // namespace mixal
mixal::Register2::set
void set(int16_t value)
Definition: registers.cpp:46
mixal::Computer::comparison
ComparisonIndicator comparison
Definition: machine.h:36
machine.h
The virtual machine.
mixal::Computer::overflow
bool overflow
Definition: machine.h:35
mixal::Computer::rI
Register2 & rI(int index)
Definition: machine.cpp:16
mixal::Computer::rJ
Register2 rJ
Definition: machine.h:33