`include "opcodes.v" `timescale 1ns / 100ps module system; reg Clock, nReset; processor Processor ( Clock, nReset); always begin Clock = 0; #250 Clock = 1; #500 Clock = 0; #250 Clock = 0; end initial begin nReset = 1; #100 nReset = 0; #800 nReset = 1; #100 nReset = 1; #100000 $display("Too long - giving up"); $stop; $finish; end always @(posedge Clock) if ( Processor.Control.Program_Counter == 99 ) begin $display("Terminating at instruction 99\n"); @(posedge Clock); @(posedge Clock); $stop; $finish; end // status interpretation function [10*8:1] get_state; input fetch_cycle; case (fetch_cycle) 0 : get_state = "Execute"; 1 : get_state = "Fetch"; default : get_state = "*ERR*"; endcase endfunction wire [10*8:1] State; assign State = get_state(Processor.Control.state); function [6*8:1] get_mnemonic; input [15:0] instruction; case (instruction[15:12]) `NOP : get_mnemonic = "NOP "; `JMP : get_mnemonic = "JMP "; `JMPZ : get_mnemonic = "JMPZ "; `JMPNZ : get_mnemonic = "JMPNZ "; `LDA : get_mnemonic = "LDA "; `ADD : get_mnemonic = "ADD "; `SUB : get_mnemonic = "SUB "; `AND : get_mnemonic = "AND "; `OR : get_mnemonic = "OR "; `NOT : get_mnemonic = "NOT "; `LSL : get_mnemonic = "LSL "; `LSR : get_mnemonic = "LSR "; `STA : get_mnemonic = "STA "; default : get_mnemonic = "*ERR* "; endcase endfunction wire [6*8:1] Mnemonic; assign Mnemonic = get_mnemonic(Processor.Control.Instruction_Register); function [11:0] get_operand; input [15:0] instruction; get_operand = instruction[11:0]; endfunction function [1*8:1] get_digit_zero; input [15:0] number; get_digit_zero = "0" + (number%10); endfunction function [1*8:1] get_digit; input [15:0] number; if ( number > 0 ) get_digit = get_digit_zero(number); else get_digit = " "; endfunction function [10*8:1] disassemble; input [15:0] instruction; disassemble = { get_mnemonic(instruction), get_digit(instruction[11:0]/1000), get_digit(instruction[11:0]/100), get_digit(instruction[11:0]/10), get_digit_zero(instruction[11:0]) }; endfunction wire [10*8:1] InstructionText; assign InstructionText = disassemble(Processor.Control.Instruction_Register); reg [10*8:1] DisassemblyListing [ 255:0 ]; integer i; initial begin #1 for ( i = 0; i < 256; i = i + 1 ) DisassemblyListing[i] = disassemble(Processor.Memory.Data_stored[i]); end endmodule