Init
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("Hello World\n");
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "../includes/opcodes.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define OPCODECOUNT 34
|
||||
|
||||
struct _instruction {
|
||||
char* Name;
|
||||
Mnemonic Mnemonic;
|
||||
};
|
||||
|
||||
struct _instruction instructions[OPCODECOUNT] = {
|
||||
{ "copya", COPYA },
|
||||
{ "copyab", COPYAB },
|
||||
{ "copyra", COPYRA },
|
||||
{ "copyrab", COPYRAB },
|
||||
{ "copyrara", COPYRARA },
|
||||
{ "copyrarab", COPYRARAB },
|
||||
{ "copy", COPY },
|
||||
{ "copyi", COPYI },
|
||||
{ "copyb", COPYB },
|
||||
{ "cmp", CMP },
|
||||
{ "cmpi", CMPI },
|
||||
{ "add", ADD },
|
||||
{ "sub", SUB },
|
||||
{ "and", AND },
|
||||
{ "xor", XOR },
|
||||
{ "or", OR },
|
||||
{ "not", NOT },
|
||||
{ "shr", SHR },
|
||||
{ "shl", SHL },
|
||||
{ "inc", INC },
|
||||
{ "dec", DEC },
|
||||
{ "push", PUSH },
|
||||
{ "pop", POP },
|
||||
{ "jmpi", JMPI },
|
||||
{ "jmp", JMP },
|
||||
{ "jz", JZ },
|
||||
{ "jg", JG },
|
||||
{ "jl", JL },
|
||||
{ "nop", NOP },
|
||||
{ "call", CALL },
|
||||
{ "ret", RET }
|
||||
//yld
|
||||
};
|
||||
|
||||
void GetMnemonicText(Mnemonic mnemonic, char buffer[12]) {
|
||||
memset(buffer, '\0', 12);
|
||||
|
||||
for(int i = 0; i < OPCODECOUNT; i++) {
|
||||
if (instructions[i].Mnemonic == mnemonic) {
|
||||
strncpy(buffer, instructions[i].Name, 11);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetRegisterText(Registers reg, char buffer[4]) {
|
||||
memset(buffer, '\0', 4);
|
||||
|
||||
if (reg < R1 || reg > R8) return;
|
||||
|
||||
buffer[0] = 'r';
|
||||
buffer[1] = reg + 49;
|
||||
}
|
||||
|
||||
int IsOpcode(const char* text, Mnemonic* opcode) {
|
||||
if (!text) return 0;
|
||||
|
||||
for(unsigned long i = 0; i < sizeof(instructions) / sizeof(struct _instruction); i++) {
|
||||
if (strcmp(instructions[i].Name, text) == 0) {
|
||||
if (opcode) *opcode = instructions[i].Mnemonic;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IsRegister(const char* text, Registers* reg) {
|
||||
if (!text) return 0;
|
||||
|
||||
int length = strlen(text);
|
||||
Registers r = R8;
|
||||
|
||||
if (length != 2) return 0;
|
||||
if (text[0] != 'r') return 0;
|
||||
|
||||
if (!isdigit(text[1])) return 0;
|
||||
|
||||
r = text[1] - 0x31;
|
||||
|
||||
if (reg) *reg = r;
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user