2013-05-17 1 views
-1

내 ALU 용 테스트 벤치를 작성하려하지만 임씨는 초보자 용입니다. 임씨는 그것이 작동하도록 작성된 것인지 확실하지 않습니다. 예를 들어 내가 dut 또는 uut을 사용해야합니까? 입력을 올바르게 초기화 했습니까? 출력 웨이브는 각 비트 X와 하나의 0으로 바뀌지 않습니다. 모든 통찰력은 크게 감사 할 것입니다. ALU Verilog 테스트 벤치가 제대로 초기화되지 않았습니까?

module Alu_test(); 
    reg [7:0]pc; 
    reg [3:0] CCRin; 
    reg rst,clk; 
    reg [3:0] opcode; 
    reg[7:0] ra; 
    reg[7:0] rb; 
    reg [7:0] in_port; 
    reg[7:0] SP;   //= 255 
    wire[7:0] SP_out; 
    wire [7:0] out_port; 
    wire[255:0] dmem; 
    wire[7:0] ra_out; 
    wire[7:0] rb_out; 
    wire [3:0] CCRo; 
    wire [7:0] npc; 


ALU dut(opcode,ra,rb,ra_out,rb_out,rst,clk,pc,npc,CCRin,CCRo,SP,SP_out,in_port,out_port,dmem); 
initial 
begin 
rst = 0; 
clk = 0; 
opcode = 0; 
SP = 255; 
CCRin = 0; 
pc = 0; 
in_port = 0; 
ra = 0; 
rb = 0; 
#5 
forever 
    #5 clk = ~clk; 

#50 

#5 opcode[3:0] = 4'b0000; //nop 


#5 opcode[3:0] = 4'b0100; //add 
ra =1; 
rb =1; 

#5 opcode[3:0] = 4'b0111; //shift left 
ra =1; 
rb =0; 

#5 opcode[3:0] = 4'b1010; //push 
ra =1; 
rb =2; 

end 
endmodule 

인스턴스 이름 미세 그대로 사용 dut 모듈

module ALU(opcode,ra,rb,ra_out,rb_out,rst,clk,pc,npc,CCRin,CCRo,SP,SP_out,in_port,out_port,dmem); 
    wire [7:0] res; // result 
    input wire [7:0]pc; 
    output reg [7:0] npc; 
    input rst,clk; 
    input wire [3:0] opcode; 
    input wire[7:0] ra; 
    input wire[7:0] rb; 
    output reg[7:0] ra_out; 
    output reg[7:0] rb_out; 
    input wire[7:0] SP; // testbench haygebli SP el mafroud yeb2a = 255 
    output reg[7:0] SP_out; 
    input wire [7:0] in_port; 
    output reg [7:0] out_port; 

    output reg[255:0] dmem; 

    input wire [3:0] CCRin; 
    output reg [3:0] CCRo; 
    wire co; 
    wire cin; 

    wire [7:0] result; //total result 

always @(posedge clk) 
    begin 
    SP_out = SP; 
end 

    assign result = alu_out(ra,rb,cin); 
    assign res = result[1:0]; 
    assign co = result[2]; 



    function [8:0] alu_out; 
    input [1:0] ra,rb; 
    input cin; 

    case (opcode) 
    0: ; 
    4: assign alu_out = ra + rb; 
    5: assign alu_out = ra - rb; 
    6: assign alu_out = ~(ra & rb); 
    7: assign alu_out = {ra[7:0],cin}; 
    8: assign alu_out = {ra[0],cin,ra[7:1]}; 
    10: if (ra == 1) 
      begin 
     dmem[SP_out] = rb; 
     SP_out = SP_out-1; 
     end 
    else 
     begin 
     SP_out = SP_out +1; 
     rb_out = dmem[SP_out]; 
    end 
    11: assign out_port = ra; 
    12: assign ra_out = in_port; 
    13: assign ra_out = rb; 
    default: begin 
    alu_out = 8'bxxxxxxxx; 


end 
endcase 
endfunction 
    [email protected](posedge clk) 
    begin 
    if (res == 0) 
    CCRo[0] = 1; 
    else if (res < 0) 
    CCRo[1] = 1; 
    else if (co == 1) 
    CCRo[2] = 1; 
    else if (res < 0 & res > result) 
    CCRo[3] = 1; 
    else 
    CCRo = CCRin; 
    if (res) 
    ra_out = res; 

    npc = pc+1; 
end 
endmodule 
+1

코드가 실제로 컴파일됩니까? 나는 행동 케이스 블록 안에 statement를 할당하는 것은 불법이라고 생각한다. '4 : alu_out = ...'을'assign '하지 말아야한다. – Tim

답변

1

이다. 원하는 경우 uut을 대신 사용할 수도 있습니다.

당신은 원래 initial 블록의 끝에서 $finish를 호출, 자신의 initial 블록으로 클럭 생성을 이동해야합니다. 이렇게하면 더 나아질거야. 이제 4 개 신호는 알려져 :

initial begin 
    rst = 0; 
    opcode = 0; 
    SP = 255; 
    CCRin = 0; 
    pc = 0; 
    in_port = 0; 
    ra = 0; 
    rb = 0; 
    #5; 
    #50; 
    #5 opcode[3:0] = 4'b0000; //nop 
    #5 opcode[3:0] = 4'b0100; //add 
    ra =1; 
    rb =1; 
    #5 opcode[3:0] = 4'b0111; //shift left 
    ra =1; 
    rb =0; 
    #5 opcode[3:0] = 4'b1010; //push 
    ra =1; 
    rb =2; 
    $finish; 
end 

initial begin 
    clk = 0; 
    forever #5 clk = ~clk; 
end 

귀하의 dmem 당신은 다른 값으로 설정 = 옵 코드에서 운전 10이 필요합니다 (X)에 초기화합니다.

+1

dmem_out과 dmem_in을 만들어 dmem을 수정하고 테스트 벤치에서 초기화하고 u가 말한 것을 수행했습니다. 도움을 준 도구 감사합니다! – Noha

+0

코드는 여전히 유용한 출력을 가져 오지 않습니다 .. 나는 논리적 오류가 있다고 생각합니다. – Noha