Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple RiSC Core with 16 bit instructions

Status
Not open for further replies.

2wice

Junior Member level 1
Junior Member level 1
Joined
Oct 30, 2013
Messages
17
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
118
I have to simulate a RiSC processor in Xilinx. But when I use this code to run a .dat file the output seems wrong . I'd be happy if anyone could point out any mistakes I'm doing in the code.



Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
`define ADD 3'd0
`define ADDI    3'd1
`define NAND    3'd2
`define LUI 3'd3
`define SW  3'd4
`define LW  3'd5
`define BNE 3'd6
`define JALR    3'd7
`define EXTEND  3'd7
 
`define IOP 15:13   // opcode
`define IRA 12:10   // rA 
`define IRB 9:7 // rB 
`define IRC 2:0 // rC 
`define IIM 6:0 // immediate (7-bit, to be sign-extended)
`define ILI 9:0 // large unsigned immediate (10-bit, to be 0-extended)
`define ISB 6   // immediate's sign bit
 
`define ZERO        16'd0
 
`define HALTINSTRUCTION { `EXTEND, 3'd0, 3'd0, 3'd7, 4'd1 }
 
module RiSC (clk);
    input       clk;
    reg     [15:0]  rf[0:7];
    reg     [15:0]  pc;
    reg     [15:0]  m[0:65535];
    reg     [15:0] m1;
    reg      [2:0] iop,ira,irb,irc;
    reg      [6:0] iim;
    reg      [9:0] ili;
    wire      isb;
    reg      [15:0] imm, imma;
    
    
    always @(negedge clk) begin
    rf[0] <= `ZERO;
    end
assign isb = m[pc[6]];
    always @(posedge clk) begin
    m1 = m[pc];
    iop = m[pc[15:13]];
        ira = m[pc[12:10]];
        irb = m[pc[9:7]];
        irc = m[pc[2:0]];
    iim = m[pc[6:0]];
    ili = m[pc[9:0]];
    
    imm = {ili,5'b0};
    
    if( iop == ADD) begin 
    rf[ira] <= rf[irb] + rf [irc];
    pc <= pc + 1;
    end
    
    else if (iop == ADDI) begin
    if(!isb) begin  
    rf[ira] <= rf[irb] + iim;
    pc <= pc+1;
    end
    else if(isb) begin
    rf[ira] <= rf[irb] - iim;
     pc <= pc+1;
    end
    end
    
    else if (iop == NAND) begin
    rf[ira] <= ~(rf[irb] && rf[irc]);
    pc <= pc+1;
    end
    
    else if (iop == LUI) begin
    imm = {ili,5'b0};
    rf[ira] <= imm;
    pc <= pc + 1;
    end 
    
    else if (iop == SW) begin
    if (!isb) begin
    imma <= iim + rf[irb];
    m[imma] <= rf[ira];
    pc <= pc+1;
    end
    else if (isb) begin
    imma <= rf[irb] - {10'b0,iim[5:0]};
    m[imma] <= rf[ira];
    pc <= pc+1;
    end 
    end
 
    else if (iop == LW) begin
    if (!isb) begin
    imma <= iim + rf[irb];
    rf[ira] <=  m[imma] ;
    pc <= pc+1;
    end
    else if (isb) begin
    imma <= rf[irb] - {10'b0,iim[5:0]};
    rf[ira]  <= m[imma] ;
    pc <= pc+1;
    end 
    end
    
    else if (iop == BNE) begin
    if (rf[ira] != rf[irb])
    begin
    if (!isb)
    pc <= pc + 1 + iim;
    else if (isb)
    pc <= pc + 1 + {10'b0,iim[5:0]};
    end
    else 
    pc <= pc+1;
    end 
    
    else if (iop == JALR) begin
    pc <= rf [irb];
   ira <= pc + 1;
    end
        
    else if (iop == `HALTINSTRUCTION) begin
    pc <= 0;
    $stop;
    end 
    end
endmodule

 
Last edited:

Well, I dont know how you compiled this, as the $stop Task is for simulation only, not synthesis.
But have you written a testbench? have you tested the code yourself?
 

Well, I dont know how you compiled this, as the $stop Task is for simulation only, not synthesis.
But have you written a testbench? have you tested the code yourself?

This program is only for simulation. I have a top module for this which feeds the clock signal as well as the memory. After every clock cycle it reads the contents of the register. The problem is I am getting the output but the output isn't the same as the expected output.
 
third line :NAND is key word,,so you mustn't use
 

it becomes red word
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top