Skip to content

Commit

Permalink
Added INP and OUT instructions, hopefully this makes Pancake happy heh
Browse files Browse the repository at this point in the history
  • Loading branch information
tryhardsnipehrd committed Dec 28, 2021
1 parent 53def65 commit 22565ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
THL.exe
THL.exe
.vs
28 changes: 26 additions & 2 deletions interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ BNE -- Branch if Not Equal to. Branches to the label if the CHK flag is NOT set
#include <string>
#include <map>

// Weird hackery, don't question it, it stops the errors.
#define nop

// Define all memory here
int xReg = 0;
int yReg = 0;
Expand Down Expand Up @@ -530,6 +533,8 @@ int LD_Star (std::vector<std::string> parseLine, std::string insStr, int expArgs
return 0;
}



int main(int argc, char * argv[]) {
// Make sure they actually specified a file
if (argc == 1){
Expand Down Expand Up @@ -789,11 +794,30 @@ int main(int argc, char * argv[]) {
break;

// Input/Output Instructions
/*
INP Function
Usage: INP <Memory Address>
Takes the INPut from user, and stores it into <Memory Address>
*/
case INP:

if (lineCode.size() != 2) {
std::cout << "INP got " << lineCode.size() - 1 << " arguments, and expected 1.\n";
return -1;
} else {
// Take the input, it will only allow integer numbers, so no decimals or strings...
std::cin >> tempNum;
memory[stoi(lineCode[1], nullptr, 0)] = tempNum;
}
break;
case OUT:

if (lineCode.size() != 2) {
std::cout << "OUT got " << lineCode.size() - 1 << " arguments, and expected 1.\n";
return -1;
} else {
// We are assuming the programmer knows to use numbers, so we are not checking it first
// Don't mess it up
std::cout << memory[stoi(lineCode[1], nullptr, 0)] << "\n";
}
break;

// Control Flow Instructions
Expand Down
3 changes: 2 additions & 1 deletion test.thl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
INP
INP 0x01
OUT 0x01

0 comments on commit 22565ea

Please sign in to comment.