MIXAL
machine_comparison.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "machine.h"
3 
9 namespace mixal {
10 
15 void Computer::executeCMP(const InstructionWord& instruction, Register5* reg) {
16  ComputerWord a, b;
17  int32_t address = getIndexedAddress(instruction, true);
18  copyToRegister5(instruction, *reg, &a);
19  copyToRegister5(instruction, memory[address], &b);
20  int32_t aVal = a.value(), bVal = b.value();
21  if (aVal < bVal) {
22  comparison = ComparisonIndicator::LESS;
23  } else if (aVal > bVal) {
24  comparison = ComparisonIndicator::GREATER;
25  } else {
26  comparison = ComparisonIndicator::EQUAL;
27  }
28 }
29 
34 void Computer::executeCMPi(const InstructionWord& instruction) {
35  int registerIndex = instruction.operation() - Instructions::CMP1 + 1;
36  auto& rIi = rI(registerIndex);
37  ComputerWord t(rIi.negative, 0, 0, 0, rIi.byte1, rIi.byte2), a, b;
38  int32_t address = getIndexedAddress(instruction, true);
39  copyToRegister5(instruction, t, &a);
40  copyToRegister5(instruction, memory[address], &b);
41  int32_t aVal = a.value(), bVal = b.value();
42  if (aVal < bVal) {
43  comparison = ComparisonIndicator::LESS;
44  } else if (aVal > bVal) {
45  comparison = ComparisonIndicator::GREATER;
46  } else {
47  comparison = ComparisonIndicator::EQUAL;
48  }
49 }
50 
51 }; // namespace mixal
mixal::Computer::memory
ComputerWord memory[NUM_MEMORY]
Definition: machine.h:38
mixal::Computer::comparison
ComparisonIndicator comparison
Definition: machine.h:36
machine.h
The virtual machine.
mixal::Computer::rI
Register2 & rI(int index)
Definition: machine.cpp:16