Compare commits
2 Commits
6a91f64fce
...
c270a48141
| Author | SHA1 | Date | |
|---|---|---|---|
| c270a48141 | |||
| 74992e673a |
5
src/device.h
Normal file
5
src/device.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
} Device;
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
#define FLAG_ZERO (1 << 0)
|
#define FLAG_ZERO (1 << 0)
|
||||||
#define FLAG_NEGATIVE (1 << 1)
|
#define FLAG_NEGATIVE (1 << 1)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const OperandType INSTRUCTION_OPERAND_TYPES[][3] = {
|
|||||||
{OP_REG, OP_REG, OP_NONE}, // JIZ
|
{OP_REG, OP_REG, OP_NONE}, // JIZ
|
||||||
{OP_REG, OP_REG, OP_NONE}, // CALL
|
{OP_REG, OP_REG, OP_NONE}, // CALL
|
||||||
{OP_NONE, OP_NONE, OP_NONE}, // RET
|
{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
|
{OP_NONE, OP_NONE, OP_NONE} // HLT
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ char* opcodeToCStr(InstructionOpcode opcode) {
|
|||||||
case INST_JIZ: return "JIZ";
|
case INST_JIZ: return "JIZ";
|
||||||
case INST_CALL: return "CALL";
|
case INST_CALL: return "CALL";
|
||||||
case INST_RET: return "RET";
|
case INST_RET: return "RET";
|
||||||
case INST_SYS: return "SYS";
|
case INST_PORT: return "PORT";
|
||||||
case INST_HLT: return "HLT";
|
case INST_HLT: return "HLT";
|
||||||
default: return "FIXME";
|
default: return "FIXME";
|
||||||
}
|
}
|
||||||
@@ -81,6 +81,14 @@ char* instructionToCStr(Instruction inst) {
|
|||||||
registerToCStr(inst.operands[opIdx])
|
registerToCStr(inst.operands[opIdx])
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case OP_IMM4:
|
||||||
|
written += snprintf(
|
||||||
|
buffer + written,
|
||||||
|
remaining,
|
||||||
|
"%d",
|
||||||
|
inst.operands[opIdx]
|
||||||
|
);
|
||||||
|
break;
|
||||||
case OP_IMM16:
|
case OP_IMM16:
|
||||||
written += snprintf(
|
written += snprintf(
|
||||||
buffer + written,
|
buffer + written,
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
// -- TYPES -- //
|
// -- TYPES -- //
|
||||||
typedef enum : uint8_t {
|
typedef enum : uint8_t {
|
||||||
INST_MOV, INST_MVI, INST_ADD, INST_SUB, INST_LOAD, INST_STORE, INST_AND, INST_OR,
|
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_XOR, INST_SHF, INST_JMP, INST_JIZ, INST_CALL, INST_RET, INST_PORT, INST_HLT
|
||||||
} InstructionOpcode;
|
} InstructionOpcode;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -38,7 +38,7 @@ typedef struct {
|
|||||||
} Instruction;
|
} Instruction;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OP_NONE, OP_REG, OP_IMM16
|
OP_NONE, OP_REG, OP_IMM4, OP_IMM16
|
||||||
} OperandType;
|
} OperandType;
|
||||||
|
|
||||||
// -- CONSTANTS -- //
|
// -- CONSTANTS -- //
|
||||||
|
|||||||
Reference in New Issue
Block a user