From 63ca6b95b1f06f18ade4e58ba7ba42b09eeeb5d5 Mon Sep 17 00:00:00 2001 From: uvok Date: Thu, 22 Jan 2026 19:43:31 +0100 Subject: Implement LDI --- eater_cpu/cpp/Veater_computer__main.cpp | 2 ++ eater_cpu/eater_decoder.sv | 8 ++++++++ eater_cpu/eater_types.sv | 4 ++++ eater_cpu/readme.txt | 1 + 4 files changed, 15 insertions(+) diff --git a/eater_cpu/cpp/Veater_computer__main.cpp b/eater_cpu/cpp/Veater_computer__main.cpp index fbfc978..4de8454 100644 --- a/eater_cpu/cpp/Veater_computer__main.cpp +++ b/eater_cpu/cpp/Veater_computer__main.cpp @@ -29,6 +29,8 @@ void load_program(const std::unique_ptr &topp) { // OUT 0xe0, + // LDI 4 + 0x54, // NOP 0x00, // HALT diff --git a/eater_cpu/eater_decoder.sv b/eater_cpu/eater_decoder.sv index fea00e0..20e3e0b 100644 --- a/eater_cpu/eater_decoder.sv +++ b/eater_cpu/eater_decoder.sv @@ -30,6 +30,7 @@ function CpuState insdep_state; ADD: insdep_state = ADD_INS_to_MAR; SUB: insdep_state = SUB_INS_to_MAR; STA: insdep_state = STA_INS_to_MAR; + LDI: insdep_state = LDI_INS_to_A; OUT: insdep_state = OUT_A_to_OUT; HALT_op: insdep_state = HALT_st; @@ -65,6 +66,8 @@ always @(posedge clk_i) begin STA_INS_to_MAR: next_state = STA_A_to_MEM; STA_A_to_MEM: next_state = PC_to_MAR; + LDI_INS_to_A: next_state = PC_to_MAR; + OUT_A_to_OUT: next_state = PC_to_MAR; HALT_st: next_state = HALT_st; @@ -153,6 +156,11 @@ always_comb begin internal_flags.A_out = 1; end + LDI_INS_to_A: begin + internal_flags.INS_out = 1; + internal_flags.A_in = 1; + end + OUT_A_to_OUT: begin internal_flags.A_out = 1; internal_flags.OUT_in = 1; diff --git a/eater_cpu/eater_types.sv b/eater_cpu/eater_types.sv index 6f69b4b..43e3a0d 100644 --- a/eater_cpu/eater_types.sv +++ b/eater_cpu/eater_types.sv @@ -44,6 +44,9 @@ typedef enum logic[7:0] { // STA: b) A -> MEM STA_A_to_MEM, + // LDI: a) LSB of INStruction into A + LDI_INS_to_A, + // OUT: A -> OUT OUT_A_to_OUT, @@ -57,6 +60,7 @@ typedef enum logic[3:0] { ADD = 'b0010, SUB = 'b0011, STA = 'b0100, + LDI = 'b0101, OUT = 'b1110, HALT_op = 'b1111 } eater_instruction; diff --git a/eater_cpu/readme.txt b/eater_cpu/readme.txt index 402f0bb..57c65ef 100644 --- a/eater_cpu/readme.txt +++ b/eater_cpu/readme.txt @@ -33,6 +33,7 @@ LDA 0b_0001_ Load memory > A ADD 0b_0010_ "Add memory": mem>B, A + B -> A SUB 0b_0011_ "Sub memory": mem>B, A - B-> A STA 0b_0100_ Store A -> memory +LDI 0b_0101_ Store -> A OUT ____________ 0b_1110_xxxx Output A -> OUT HLT ____________ 0b_1111_xxxx Sets halt flag --- -- cgit v1.2.3