/*
* Unnamed 8-bit processing unit
* Made by github.com/xamidev
*
* This is free and unencumbered software released into the public domain.
* For more information, please refer to
*/
#include
#include
#include
#include
#include
#define MEM_SIZE 256
#define NUM_REGISTERS 4
/*
* Instruction set
* Here, we're making a RISC (reduced instruction set computer)
* so we're staying minimalistic.
*/
typedef enum
{
MOV = 1,
ADD,
SUB,
LOAD,
STORE,
JMP,
JEQ,
HLT = 0xFF
} instruction_set_t;
/*
* CPU structure definition
* Contains 4 8-bit registers, memory, a program counter, and a halt switch.
*/
typedef struct
{
uint8_t reg[NUM_REGISTERS];
uint8_t memory[MEM_SIZE];
uint16_t pc;
bool halted;
} CPU_t;
CPU_t cpu;
/*
* Initializing the CPU: program counter and registers to zero, halted flag to false.
*/
void cpu_init()
{
cpu.pc = 0;
cpu.halted = false;
for (size_t i=0; i\n", argv[0]);
return -1;
}
assemble(argv[1]);
// Dumping our program
mem_dump();
cpu_run();
// Post-mortem analysis
cpu_dump();
return 0;
}