/3/2/RAM4K.hdl

http://github.com/happy4crazy/elements_of_computing_systems · Unknown · 51 lines · 45 code · 6 blank · 0 comment · 0 complexity · bfc664d6da8366e08528d861426f5eac MD5 · raw file

  1. // This file is part of the materials accompanying the book
  2. // "The Elements of Computing Systems" by Nisan and Schocken,
  3. // MIT Press. Book site: www.idc.ac.il/tecs
  4. // File name: projects/03/2/RAM4K.hdl
  5. /**
  6. * Memory of 4K registers, each 16-bit wide.
  7. * The chip facilitates read and write operations, as follows:
  8. * Read: out(t) = RAM4K[address(t)](t)
  9. * Write: If load(t-1) then RAM4K[address(t-1)](t) = in(t-1)
  10. * In words: the chip always outputs the value stored at the memory
  11. * location specified by address. If load=1, the in value is loaded
  12. * into the memory location specified by address. This value becomes
  13. * available through the out output starting from the next time step.
  14. */
  15. CHIP RAM4K {
  16. IN in[16], load, address[12];
  17. OUT out[16];
  18. PARTS:
  19. DMux8Way(in=load, sel=address[0..2],
  20. a=load0,
  21. b=load1,
  22. c=load2,
  23. d=load3,
  24. e=load4,
  25. f=load5,
  26. g=load6,
  27. h=load7);
  28. RAM512(in=in, load=load0, address=address[3..11], out=out0);
  29. RAM512(in=in, load=load1, address=address[3..11], out=out1);
  30. RAM512(in=in, load=load2, address=address[3..11], out=out2);
  31. RAM512(in=in, load=load3, address=address[3..11], out=out3);
  32. RAM512(in=in, load=load4, address=address[3..11], out=out4);
  33. RAM512(in=in, load=load5, address=address[3..11], out=out5);
  34. RAM512(in=in, load=load6, address=address[3..11], out=out6);
  35. RAM512(in=in, load=load7, address=address[3..11], out=out7);
  36. Mux8Way16(a=out0,
  37. b=out1,
  38. c=out2,
  39. d=out3,
  40. e=out4,
  41. f=out5,
  42. g=out6,
  43. h=out7,
  44. sel=address[0..2], out=out);
  45. }