Pages

Sunday 22 June 2014

Write a verilog code to swap contents of two registers with and without a temporary register?

With temp register (using blocking assignment)

always @ (posedge clock)
   begin
     temp = b;
     b = a;
     a = temp;
   end
 
Without temp register (using non-blocking assignment)

always @ (posedge clock)
   begin
     a <= b;
     b <= a;
   end

12 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Rajeev, you can refer the internal phasing
    http://www.microelectronicslab.com/KnowBase/Verilog-IQ.html#Q2

    ReplyDelete
  3. a and b will be as input or wire ...i hv been trying but give complet code plz

    ReplyDelete
    Replies
    1. Hi,
      We have uploaded the complete code. please try it out.
      enjoy and keep learning ,keep sharing :-)

      Regards,
      Rajeev

      Delete
    2. where is the complete code

      Delete

  4. module swap(input[1:0]a,b,
    input clk);
    reg[1:0]tempa,tempb,temp; //reg tempb;
    always @ (posedge clk)
    begin
    tempa = a;
    tempb = b;
    temp=tempa;
    tempa = tempb;
    tempb = temp ;
    end
    endmodule

    ReplyDelete
  5. module swap(clk);
    input clk;
    integer a,b,temp;
    initial
    begin
    a = 10; b = 20;
    end

    always@(posedge clk)
    begin
    #50temp=b;
    #50b=a;
    #50a=temp;
    end
    endmodule

    ReplyDelete
  6. Module register(D,clk,RST,Q);
    Input D;
    Input clk;
    Input RST;
    Output reg Q;
    Always@(posedge clk)
    If(!RST)
    Q<=0;
    Else
    Q<=D;
    Else
    Q=1;
    Endmodule

    ReplyDelete
  7. 8bit number from dip switch and swap the nibble and display on led

    ReplyDelete