Perrine

Lab 6

Oct 8th, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module main(clk, out
  2.     );
  3.      
  4.      input clk;
  5.      output out;
  6.      wire clk;
  7.      reg[7:0] out;
  8.      
  9.      reg[31:0] instru_mem[7:0], register[7:0];
  10.      reg[31:0] instruction;
  11.      reg[2:0] PC;
  12.      
  13.     initial begin
  14.         out = 0;
  15.         PC = 0;
  16.         register[0] = 0;
  17.         register[1] = 0;
  18.         register[2] = 0;
  19.         register[3] = 0;
  20.         register[4] = 0;
  21.         register[5] = 3;
  22.         register[6] = 6;
  23.         register[7] = 0;
  24.        
  25.         instru_mem[0] = 32'b00000000110001010011100000000010;
  26.         instru_mem[1] = 32'b00000000110001010011100000000100;
  27.         instru_mem[2] = 32'b00000000110001010011100000000000;
  28.         instru_mem[3] = 32'b00000000110001010011100000000001;
  29.         instru_mem[4] = 0;
  30.         instru_mem[5] = 0;
  31.         instru_mem[6] = 0;
  32.         instru_mem[7] = 0;
  33.     end
  34.    
  35.     always@(posedge clk) begin
  36.         instruction = instru_mem[PC];
  37.         PC = PC+1;
  38.     end
  39.    
  40.     always@(PC) begin
  41.         if(instruction[5:0] == 0) begin
  42.             register[instruction[15:11]] <= register[instruction[25:21]] & register[instruction[20:16]];
  43.         end else
  44.         if(instruction[5:0] == 1) begin
  45.             register[instruction[15:11]] <= register[instruction[25:21]] | register[instruction[20:16]];
  46.         end else
  47.         if(instruction[5:0] == 2) begin
  48.             register[instruction[15:11]] <= register[instruction[25:21]] + register[instruction[20:16]];
  49.         end else
  50.         if(instruction[5:0] == 4) begin
  51.             register[instruction[15:11]] <= register[instruction[25:21]] - register[instruction[20:16]];
  52.         end
  53.        
  54.         out = register[7][7:0];
  55.    
  56.     end
  57.    
  58.      
  59. endmodule
Advertisement