53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
/*
|
|
PlutoISA
|
|
Copyright (C) 2024 Patrick_Pluto
|
|
|
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
Please note that the assembled code that gets output from this program is NOT under the GPL, and can be licensed under any other license at your choice.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <fstream>
|
|
#include <cstdlib>
|
|
#include <cstdint>
|
|
|
|
using namespace std;
|
|
|
|
void assemble ( vector<string> tokens, uint8_t *rom ) {
|
|
int index = 0;
|
|
|
|
for ( const auto& part : tokens ) {
|
|
if ( part == "GET" ) {
|
|
rom[index] = 0x00;
|
|
} else if ( part == "LOAD" ) {
|
|
rom[index] = 0x01;
|
|
} else if ( part == "STORE" ) {
|
|
rom[index] = 0x02;
|
|
} else if ( part == "ADD" ) {
|
|
rom[index] = 0x03;
|
|
} else if ( part == "SUB" ) {
|
|
rom[index] = 0x04;
|
|
} else if ( part == "JMP" ) {
|
|
rom[index] = 0x05;
|
|
} else if ( part == "JEQ" ) {
|
|
rom[index] = 0x06;
|
|
} else if ( part == "HIN" ) {
|
|
rom[index] = 0x07;
|
|
} else {
|
|
uint8_t value = stoi(part, nullptr, 16);
|
|
rom[index] = value;
|
|
}
|
|
index += 1;
|
|
}
|
|
}
|
|
|