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. --- Makefile | 2 +- hdl/top.sv | 31 +++++++++++++++++++++++-------- mem/mem.hex | 55 +++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index f4a0da8..24e2692 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ sim: build/Vtop build/Vtop: $(SOURCES) $(COLLATERAL) @mkdir -p build - verilator +1800-2017ext+sv -Wall -Wno-BLKSEQ -Wno-UNUSED -O3 -Ihdl $(OPTS) --Mdir build --trace --cc --build -j --exe --top-module top $(SOURCES) + verilator +1800-2017ext+sv -Wall -Wno-BLKSEQ -Wno-UNUSED -Wno-WIDTH -O3 -Ihdl $(OPTS) --Mdir build --trace --cc --build -j --exe --top-module top $(SOURCES) clean: rm -rf build 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 diff --git a/mem/mem.hex b/mem/mem.hex index 6d096bb..7923fb7 100644 --- a/mem/mem.hex +++ b/mem/mem.hex @@ -1,18 +1,41 @@ @0 -048 100 // H -065 100 // e -06c 100 // l -06c 100 // l -06f 100 // o -02c 100 // , -020 100 // ' ' -077 100 // w -06f 100 // o -072 100 // r -06c 100 // l -064 100 // d -021 100 // ! -00a 100 // \n - -700 +040 // %acc = 0x40 +f20 // %idx = %acc + +// loop: (addr 2) +100 // %acc = [%idx] +300 402 // if (%acc == 0) { %pc = exit } +f44 // ++%idx; tx %acc +4fb // jmp loop +// exit: (addr 7) + +f80 // hcf + +@40 + +048 // H +065 // e +06c // l +06c // l +06f // o +02c // , +020 // ' ' +077 // w +06f // o +072 // r +06c // l +064 // d +021 // ! +00a // \n + +000 + +04f // O +06f // o +070 // p +073 // s +021 // ! +00a // \n + +000 -- cgit v1.2.3