diff --git a/cpu.c b/cpu.c index 3547927..8b44752 100644 --- a/cpu.c +++ b/cpu.c @@ -28,15 +28,16 @@ typedef enum // 0xA? -> Memory operations MOV = 0xA0, - LOAD = 0xA1, - STORE = 0xA2, // 0xB? -> Arithmetic operations ADD = 0xB0, SUB = 0xB1, // 0xC? -> Bitwise operations - + OR = 0xC0, + AND = 0xC1, + XOR = 0xC2, + // 0xE? -> Jump and comparisons JMP = 0xE0, JEQ = 0xE1, @@ -98,6 +99,7 @@ void cpu_exec(uint8_t opcode) switch (opcode) { + // Some lines are repeating.. Should make this a better way.. case NOP: break; case MOV: @@ -115,6 +117,21 @@ void cpu_exec(uint8_t opcode) reg2 = cpu.memory[cpu.pc++]; cpu.reg[reg1] -= cpu.reg[reg2]; break; + case OR: + reg1 = cpu.memory[cpu.pc++]; + reg2 = cpu.memory[cpu.pc++]; + cpu.reg[reg1] |= cpu.reg[reg2]; + break; + case AND: + reg1 = cpu.memory[cpu.pc++]; + reg2 = cpu.memory[cpu.pc++]; + cpu.reg[reg1] &= cpu.reg[reg2]; + break; + case XOR: + reg1 = cpu.memory[cpu.pc++]; + reg2 = cpu.memory[cpu.pc++]; + cpu.reg[reg1] ^= cpu.reg[reg2]; + break; case HLT: cpu.halted = true; break; @@ -210,6 +227,24 @@ void assemble(const char* filename) cpu.memory[mem_index++] = reg1_n; cpu.memory[mem_index++] = reg2_n; } + else if (strncmp(instruction, "OR", 2) == 0) + { + cpu.memory[mem_index++] = OR; + cpu.memory[mem_index++] = reg1_n; + cpu.memory[mem_index++] = reg2_n; + } + else if (strncmp(instruction, "AND", 3) == 0) + { + cpu.memory[mem_index++] = AND; + cpu.memory[mem_index++] = reg1_n; + cpu.memory[mem_index++] = reg2_n; + } + else if (strncmp(instruction, "XOR", 3) == 0) + { + cpu.memory[mem_index++] = XOR; + cpu.memory[mem_index++] = reg1_n; + cpu.memory[mem_index++] = reg2_n; + } } else if (sscanf(line, "%s %[^,], %d", instruction, reg1, &addr) == 2) { int reg1_n = reg1[1] - '0'; @@ -288,8 +323,6 @@ void mem_dump() { // Instructions (colored background) case 0xa0: - case 0xa1: - case 0xa2: printf("\e[42m%02x\e[0m ", cpu.memory[i]); break; @@ -298,6 +331,12 @@ void mem_dump() printf("\e[43m%02x\e[0m ", cpu.memory[i]); break; + case 0xc0: + case 0xc1: + case 0xc2: + printf("\e[45m%02x\e[0m ", cpu.memory[i]); + break; + case 0xe0: case 0xe1: case 0xe2: @@ -346,7 +385,8 @@ int main(int argc, char* argv[]) // Dumping our program mem_dump(); - + + reg_write(1, 0x12); reg_write(2, 0x10); cpu_run(); diff --git a/program.asm b/program.asm index 85c3728..69ffcec 100644 --- a/program.asm +++ b/program.asm @@ -1,6 +1,5 @@ ;this is a comment -ADD R1, R2 -SUB R1, R2 -SUB R1, R2 +OR R1, R2 + HLT