Compare commits

..

2 Commits

4 changed files with 19 additions and 5 deletions

5
src/device.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
typedef struct {
} Device;

View File

@@ -5,6 +5,7 @@
#include <string.h>
#include <stdbool.h>
#include "memory.h"
#include "device.h"
#define FLAG_ZERO (1 << 0)
#define FLAG_NEGATIVE (1 << 1)

View File

@@ -15,7 +15,7 @@ const OperandType INSTRUCTION_OPERAND_TYPES[][3] = {
{OP_REG, OP_REG, OP_NONE}, // JIZ
{OP_REG, OP_REG, OP_NONE}, // CALL
{OP_NONE, OP_NONE, OP_NONE}, // RET
{OP_REG, OP_REG, OP_REG}, // SYS
{OP_REG, OP_REG, OP_IMM4}, // PORT
{OP_NONE, OP_NONE, OP_NONE} // HLT
};
@@ -35,7 +35,7 @@ char* opcodeToCStr(InstructionOpcode opcode) {
case INST_JIZ: return "JIZ";
case INST_CALL: return "CALL";
case INST_RET: return "RET";
case INST_SYS: return "SYS";
case INST_PORT: return "PORT";
case INST_HLT: return "HLT";
default: return "FIXME";
}
@@ -81,6 +81,14 @@ char* instructionToCStr(Instruction inst) {
registerToCStr(inst.operands[opIdx])
);
break;
case OP_IMM4:
written += snprintf(
buffer + written,
remaining,
"%d",
inst.operands[opIdx]
);
break;
case OP_IMM16:
written += snprintf(
buffer + written,

View File

@@ -7,8 +7,8 @@
// -- TYPES -- //
typedef enum : uint8_t {
INST_MOV, INST_MVI, INST_ADD, INST_SUB, INST_LOAD, INST_STORE, INST_AND, INST_OR,
INST_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_SYS, INST_HLT
INST_MOV, INST_MVI, INST_ADD, INST_SUB, INST_LOAD, INST_STORE, INST_AND, INST_OR,
INST_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_PORT, INST_HLT
} InstructionOpcode;
typedef enum {
@@ -38,7 +38,7 @@ typedef struct {
} Instruction;
typedef enum {
OP_NONE, OP_REG, OP_IMM16
OP_NONE, OP_REG, OP_IMM4, OP_IMM16
} OperandType;
// -- CONSTANTS -- //