fix R0 bug

This commit is contained in:
xamidev
2024-10-24 16:28:45 +02:00
parent 6eb02b3b58
commit 59688d05c4
4 changed files with 7 additions and 9 deletions

View File

@@ -69,4 +69,4 @@ HLT
## Known bugs ## Known bugs
- R0 is not usable (confusion with NOP opcode 0 in memory) - None for now? If you find one, please open an issue.

2
cpu.c
View File

@@ -197,7 +197,7 @@ void cpu_dump()
{ {
printf("\n*** CPU state dump ***\nPC: 0x%x\nEqual flag: %d\nHalted: %d\n\n", cpu.pc, cpu.equal_flag, cpu.halted); printf("\n*** CPU state dump ***\nPC: 0x%x\nEqual flag: %d\nHalted: %d\n\n", cpu.pc, cpu.equal_flag, cpu.halted);
for (size_t i=1; i<NUM_REGISTERS; i+=2) for (size_t i=0; i<NUM_REGISTERS; i+=2)
{ {
printf("R%lu: 0x%04x R%lu: 0x%04x\n", i, cpu.reg[i], i+1, cpu.reg[i+1]); printf("R%lu: 0x%04x R%lu: 0x%04x\n", i, cpu.reg[i], i+1, cpu.reg[i+1]);
} }

8
cpu.h
View File

@@ -13,12 +13,9 @@
typedef enum typedef enum
{ {
// 0x00 -> No operation
NOP = 0,
// 0xA? -> Memory operations // 0xA? -> Memory operations
MOV = 0xA0, MOV = 0xA0,
PUT = 0xA1, PUT = 0xA1,
// 0xB? -> Arithmetic operations // 0xB? -> Arithmetic operations
ADD = 0xB0, ADD = 0xB0,
@@ -41,12 +38,13 @@ typedef enum
CMP = 0xE2, CMP = 0xE2,
// 0xF? -> Misc operations // 0xF? -> Misc operations
NOP = 0xFE,
HLT = 0xFF HLT = 0xFF
} instruction_set_t; } instruction_set_t;
/* /*
* CPU structure definition * CPU structure definition
* Contains 4 8-bit registers, memory, a program counter, a halt switch, and flags. * Contains 8-bit registers, memory, a program counter, a halt switch, and flags.
*/ */
typedef struct typedef struct

View File

@@ -1,6 +1,6 @@
;this is a comment ;this is a comment
PUT R2, 5 PUT R0, 5
PUT R3, 2 PUT R3, 2
DIV R2, R3 ADD R0, R3
HLT HLT