From 484293ae7865bf10d8bdb9c5c70982c57acfc0c9 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 28 Mar 2021 15:31:00 -0700 Subject: Some more interesting opcodes. --- hdl/top.sv | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'hdl') diff --git a/hdl/top.sv b/hdl/top.sv index 8524b63..aa5a4e2 100644 --- a/hdl/top.sv +++ b/hdl/top.sv @@ -43,6 +43,7 @@ bit [DATA_BITS-1:0] pc; bit [3:0] opcode; bit [7:0] operand; bit [DATA_BITS-1:0] acc; +bit [DATA_BITS-1:0] idx; enum { FETCH @@ -56,6 +57,7 @@ always_ff @(posedge clk) begin tx_data = 0; pc = 0; acc = 0; + idx = 0; state = state.first; end else begin if (`tx_ready) tx_valid = 0; @@ -68,18 +70,31 @@ always_ff @(posedge clk) begin end DECODE: begin + //$display("%x %x:%x (acc=%x idx=%x)", pc, opcode, operand, acc, idx); state = FETCH; case (opcode) - 'b000: acc = {{4{operand[7]}}, operand}; - 'b001: begin - if (tx_valid) begin - state = DECODE; - end else begin - tx_valid = 1; - tx_data = acc[7:0]; + 'h0: acc = {{4{operand[7]}}, operand}; + 'h1: acc = mem[idx + operand]; + 'h2: mem[idx + operand] = acc; + 'h3: if (acc != operand) ++pc; + 'h4: pc = pc + {{4{operand[7]}}, operand}; + 'hf: begin + if (operand[0]) ++acc; + if (operand[1]) --acc; + if (operand[2]) ++idx; + if (operand[3]) --idx; + if (operand[4]) {idx, acc} = {acc, idx}; + if (operand[5]) idx = acc; + if (operand[6]) begin + if (tx_valid) begin + state = DECODE; + end else begin + tx_valid = 1; + tx_data = acc[7:0]; + end end + if (operand[7]) state = DECODE; end - 'b111: state = DECODE; endcase end endcase -- cgit v1.2.3