Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. //5
  2. module reg_8_bits (
  3. input clk,
  4. input [7:0] in,
  5. output [7:0] out);
  6.  
  7. D_latch ex1(in[0], clk, out[0]);
  8. D_latch ex2(in[1], clk, out[1]);
  9. D_latch ex3(in[2], clk, out[2]);
  10. D_latch ex4(in[3], clk, out[3]);
  11. D_latch ex5(in[4], clk, out[4]);
  12. D_latch ex6(in[5], clk, out[5]);
  13. D_latch ex7(in[6], clk, out[6]);
  14. D_latch ex8(in[7], clk, out[7]);
  15.  
  16. endmodule
  17.  
  18. //5 adder_A_B_8_bits
  19. module ps4 (
  20. input [7:0] SW,
  21. input [1:0] KEY,
  22. output [9:0] LEDR,
  23. output [0:6] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5);
  24.  
  25. assign LEDR[7:0] = SW[7:0];
  26.  
  27. wire [0:7]A, B;
  28.  
  29. reg_8_bits saveA(KEY[1] ^ KEY[0], SW[7:0], A[0:7]);
  30.  
  31. assign B[0:7] = SW[7:0];
  32.  
  33. showDigitHex showA1(A[0:3], HEX3);
  34. showDigitHex showA2(A[4:7], HEX2);
  35. showDigitHex showB1(B[0:3], HEX1);
  36. showDigitHex showB2(B[4:7], HEX0);
  37.  
  38. reg [0:8]S;
  39. reg cout;
  40.  
  41. assign LEDR[9] = cout;
  42.  
  43.  
  44. always@*
  45. begin
  46. S = A + B;
  47.  
  48. if(S > 8'hFF)
  49. begin
  50. S = S - 8'hFF;
  51. cout = 1;
  52. end
  53. else
  54. cout = 0;
  55.  
  56. end
  57.  
  58. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement