diff options
Diffstat (limited to 'hdl/top.sv')
| -rw-r--r-- | hdl/top.sv | 31 |
1 files changed, 23 insertions, 8 deletions
| @@ -43,6 +43,7 @@ bit [DATA_BITS-1:0] pc; | |||
| 43 | bit [3:0] opcode; | 43 | bit [3:0] opcode; |
| 44 | bit [7:0] operand; | 44 | bit [7:0] operand; |
| 45 | bit [DATA_BITS-1:0] acc; | 45 | bit [DATA_BITS-1:0] acc; |
| 46 | bit [DATA_BITS-1:0] idx; | ||
| 46 | 47 | ||
| 47 | enum | 48 | enum |
| 48 | { FETCH | 49 | { FETCH |
| @@ -56,6 +57,7 @@ always_ff @(posedge clk) begin | |||
| 56 | tx_data = 0; | 57 | tx_data = 0; |
| 57 | pc = 0; | 58 | pc = 0; |
| 58 | acc = 0; | 59 | acc = 0; |
| 60 | idx = 0; | ||
| 59 | state = state.first; | 61 | state = state.first; |
| 60 | end else begin | 62 | end else begin |
| 61 | if (`tx_ready) tx_valid = 0; | 63 | if (`tx_ready) tx_valid = 0; |
| @@ -68,18 +70,31 @@ always_ff @(posedge clk) begin | |||
| 68 | end | 70 | end |
| 69 | 71 | ||
| 70 | DECODE: begin | 72 | DECODE: begin |
| 73 | //$display("%x %x:%x (acc=%x idx=%x)", pc, opcode, operand, acc, idx); | ||
| 71 | state = FETCH; | 74 | state = FETCH; |
| 72 | case (opcode) | 75 | case (opcode) |
| 73 | 'b000: acc = {{4{operand[7]}}, operand}; | 76 | 'h0: acc = {{4{operand[7]}}, operand}; |
| 74 | 'b001: begin | 77 | 'h1: acc = mem[idx + operand]; |
| 75 | if (tx_valid) begin | 78 | 'h2: mem[idx + operand] = acc; |
| 76 | state = DECODE; | 79 | 'h3: if (acc != operand) ++pc; |
| 77 | end else begin | 80 | 'h4: pc = pc + {{4{operand[7]}}, operand}; |
| 78 | tx_valid = 1; | 81 | 'hf: begin |
| 79 | tx_data = acc[7:0]; | 82 | if (operand[0]) ++acc; |
| 83 | if (operand[1]) --acc; | ||
| 84 | if (operand[2]) ++idx; | ||
| 85 | if (operand[3]) --idx; | ||
| 86 | if (operand[4]) {idx, acc} = {acc, idx}; | ||
| 87 | if (operand[5]) idx = acc; | ||
| 88 | if (operand[6]) begin | ||
| 89 | if (tx_valid) begin | ||
| 90 | state = DECODE; | ||
| 91 | end else begin | ||
| 92 | tx_valid = 1; | ||
| 93 | tx_data = acc[7:0]; | ||
| 94 | end | ||
| 80 | end | 95 | end |
| 96 | if (operand[7]) state = DECODE; | ||
| 81 | end | 97 | end |
| 82 | 'b111: state = DECODE; | ||
| 83 | endcase | 98 | endcase |
| 84 | end | 99 | end |
| 85 | endcase | 100 | endcase |
