Advertisement
Guest User

i

a guest
Dec 5th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. // higher level to debounce clock
  2. // done is an led
  3. // buswires are the 7-seg and leds
  4.  
  5.  
  6. module Processor(Data, w, Clock, Done, Buswires);// remove reset F, Rx, Ry. | W is the run switch | [done]
  7. input [7:0] Data;
  8. input w, Clock;
  9. output wire [7:0] Buswires;
  10. output Done;
  11. reg [0:3] Rin, Rout;
  12. reg [7:0] Sum;
  13. wire Clear, AddSub, Extern, Ain, Gin, Gout, FRin;
  14. wire [1:0] Count;
  15. wire [0:3] T,I, Xreg, Y;
  16. wire [7:0] R0, R1, R2, R3, A, G;
  17. wire [7:0] Func, FuncReg; // change to match the data 7:0[done]
  18. integer k;
  19.  
  20. upcount counter (Clear, Clock, Count);
  21. dec2to4 decT(count, 1'b1, T);
  22.  
  23. assign Clear = Done | (~w & T[0]);
  24. assign Func = Data; // make func = data
  25. assign FRin = w & T[0];
  26.  
  27. regn functionreg (Func, FRin, Clock, FuncReg); // func is input, Frin is load debounce the clock, funcreg is output
  28. defparam functionreg.n = 8; // change this to 8
  29. dec2to4 decl (FuncReg[6:4], 1'b1, I); // reorder the bits to match direction ( use a 3:8 decoder)
  30. dec2to4 decX (FuncReg[3:2], 1'b1, Xreg); // still a 2:4 decoder
  31. dec2to4 decY (FuncReg[1:0], 1'b1, Y); // still a 2:4 decoder
  32.  
  33. // 22- 27 is the instruction
  34. // you get I, Y, Xreg
  35.  
  36.  
  37. // the control signals assereted in each step, TABLE 7.2
  38. // Rin = X means Set Rxin
  39. assign Extern = I[0] & T[1];
  40. assign Done = ((I[0] | I[1]) & T[1]) | ((I[2] | I[3]) & T[3]);
  41. assign Ain = (I[2] | I[3]) & T[1];
  42. assign Gin = (I[2] | I[3]) & T[2];
  43. assign Gout = (I[2] | I[3]) & T[3];
  44. assign AddSub = I[3];
  45.  
  46. always@(I,T,Xreg,Y) // add 4 and 5 to th 2 and 3
  47. for(k=0;k<4;k=k+1)
  48. begin
  49. Rin[k]=((I[0]|I[1])&T[1]& Xreg[k])|
  50. ((I[2]|I[3])&T[3]&Xreg[k]);
  51. Rout[k]=(I[1] & T[1] & Y[k])|((I[2]|I[3])&
  52. ((T[1]&Xreg[k])|(T[2]&Y[k])));
  53. end
  54.  
  55. trin tri_ext(Data,Extern,BusWires);
  56. regn reg_0(BusWires,Rin[0],Clock,R0);
  57. regn reg_1(BusWires,Rin[1],Clock,R1);
  58. regn reg_2(BusWires,Rin[2],Clock,R2);
  59. regn reg_3(BusWires,Rin[3],Clock,R3);
  60.  
  61. trin tri_0(R0,Rout[0],BusWires);
  62. trin tri_1(R1,Rout[1],BusWires);
  63. trin tri_2(R2,Rout[2],BusWires);
  64. trin tri_3(R3,Rout[3],BusWires);
  65. regn reg_A(BusWires,Ain,Clock,A);
  66.  
  67. // this is the ALU / CPU we need add, sub, logical and, logical or, and get complement
  68. // make this a case
  69. // case (funcreg[6:4])
  70. // 3'b010: Sum = A + Bus wire
  71. // ... do the same for the other instructions
  72. always@(AddSub,A,BusWires)
  73. case (funcreg[6:4])
  74. 3'b0010:
  75. Sum = A + BusWires
  76. 3
  77. if(!AddSub)
  78. Sum = A+BusWires;
  79. else
  80. Sum = A-BusWires;
  81.  
  82. regn reg_G(Sum,Gin,Clock,G);
  83. trin tri_G(G,Gout,BusWires);
  84.  
  85. endmodule
  86.  
  87. // notes
  88.  
  89. //pin plan the data;
  90. // data is 8 bits
  91. // first 4 are the instruction
  92. // the next 2 is the X reg
  93. // the last 2 is the Y reg
  94.  
  95. // function needs to b 4 bits
  96. // need to beef up the instrction decode with a 3:8 decoder
  97. // loical and and or pg 224
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement