OpenCores
URL https://opencores.org/ocsvn/mips_16/mips_16/trunk

Subversion Repositories mips_16

[/] [mips_16/] [trunk/] [rtl/] [instruction_mem.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 Doyya
/***************************************************
2
 * Module: instruction_mem
3
 * Project: mips_16
4
 * Author: fzy
5
 * Description:
6
 *     a rom
7
 *
8
 * Revise history:
9
 *
10
 ***************************************************/
11
`timescale 1ns/1ps
12
`include "mips_16_defs.v"
13
 
14
`ifdef USE_SIMULATION_CODE
15
module instruction_mem          // a rtl simulation rom, rom initial code can be found in the testbench
16
(
17
        input                                   clk,            // asynchronized!!
18
        input   [`PC_WIDTH-1:0]  pc,
19
 
20
        output  [15:0]                   instruction
21
);
22
 
23
        reg     [15:0] rom [2**`INSTR_MEM_ADDR_WIDTH-1 : 0];
24
 
25
        wire [`INSTR_MEM_ADDR_WIDTH-1 : 0] rom_addr = pc[`INSTR_MEM_ADDR_WIDTH-1 : 0];
26
 
27
        // always @ (posedge clk) begin
28
        // always @ (*) begin
29
            // instruction = rom[rom_addr];
30
        // end
31
 
32
        assign instruction = rom[rom_addr];
33
 
34
 
35
endmodule
36
`endif
37
 
38
`ifndef USE_SIMULATION_CODE
39
module instruction_mem          // a synthesisable rom implementation
40
(
41
        input                                   clk,            // asynchronized!!
42
        input   [`PC_WIDTH-1:0]  pc,
43
 
44
        output reg      [15:0]           instruction
45
);
46
 
47
        wire [`INSTR_MEM_ADDR_WIDTH-1 : 0] rom_addr = pc[`INSTR_MEM_ADDR_WIDTH-1 : 0];
48
 
49
        // ASM code in rom:
50
        // L1:  ADDI            R1,R0,8
51
        //              ADDI            R2,R1,8
52
        //              ADDI            R3,R2,8
53
        //              ADD                     R4,R2,R3
54
        //              ST                      R4,R1,2
55
        //              LD                      R5,R1,2
56
        //              SUB                     R6,R4,R5
57
        //              BZ                      R6,L1
58
        //              ADDI            R7,R7,1
59
        always @(*)
60
                case (rom_addr)
61
                        4'b0000: instruction = 16'b1001001000001000;
62
                        4'b0001: instruction = 16'b1001010001001000;
63
                        4'b0010: instruction = 16'b1001011010001000;
64
                        4'b0011: instruction = 16'b0001100010011000;
65
                        4'b0100: instruction = 16'b1011100001000010;
66
                        4'b0101: instruction = 16'b1010101001000010;
67
                        4'b0110: instruction = 16'b0010110100101000;
68
                        4'b0111: instruction = 16'b1100000110111000;
69
                        4'b1000: instruction = 16'b1001111111000001;
70
                        4'b1001: instruction = 16'b0000000000000000;
71
                        4'b1010: instruction = 16'b0000000000000000;
72
                        4'b1011: instruction = 16'b0000000000000000;
73
                        4'b1100: instruction = 16'b0000000000000000;
74
                        4'b1101: instruction = 16'b0000000000000000;
75
                        4'b1110: instruction = 16'b0000000000000000;
76
                        4'b1111: instruction = 16'b0000000000000000;
77
                        default: instruction = 16'b0000000000000000;
78
         endcase
79
 
80
endmodule
81
`endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.