add Memory.hdl
This commit is contained in:
parent
c80301c721
commit
5259769725
53
projects/05/Memory.hdl
Normal file
53
projects/05/Memory.hdl
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// This file is part of www.nand2tetris.org
|
||||||
|
// and the book "The Elements of Computing Systems"
|
||||||
|
// by Nisan and Schocken, MIT Press.
|
||||||
|
// File name: projects/05/Memory.hdl
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The complete address space of the Hack computer's memory,
|
||||||
|
* including RAM and memory-mapped I/O.
|
||||||
|
* The chip facilitates read and write operations, as follows:
|
||||||
|
* Read: out(t) = Memory[address(t)](t)
|
||||||
|
* Write: if load(t-1) then Memory[address(t-1)](t) = in(t-1)
|
||||||
|
* In words: the chip always outputs the value stored at the memory
|
||||||
|
* location specified by address. If load==1, the in value is loaded
|
||||||
|
* into the memory location specified by address. This value becomes
|
||||||
|
* available through the out output from the next time step onward.
|
||||||
|
* Address space rules:
|
||||||
|
* Only the upper 16K+8K+1 words of the Memory chip are used.
|
||||||
|
* Access to address>0x6000 is invalid. Access to any address in
|
||||||
|
* the range 0x4000-0x5FFF results in accessing the screen memory
|
||||||
|
* map. Access to address 0x6000 results in accessing the keyboard
|
||||||
|
* memory map. The behavior in these addresses is described in the
|
||||||
|
* Screen and Keyboard chip specifications given in the book.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CHIP Memory {
|
||||||
|
IN in[16], load, address[15];
|
||||||
|
OUT out[16];
|
||||||
|
|
||||||
|
PARTS:
|
||||||
|
// Put your code here:
|
||||||
|
|
||||||
|
// 00 00000 0000 0000 <- First RAM16K Register
|
||||||
|
// 01 11111 1111 1111 <- Last RAM16K Register
|
||||||
|
// 10 00000 0000 0000 <- First SCREEN Register
|
||||||
|
// 10 11111 1111 1111 <- Last SCREEN Register
|
||||||
|
// 11 00000 0000 0000 <- One Keyboard Register
|
||||||
|
|
||||||
|
DMux4Way(in=load, sel=address[13..14], a=toRAM1,
|
||||||
|
b=toRAM2,
|
||||||
|
c=toScreen,
|
||||||
|
d=notNeeded);
|
||||||
|
|
||||||
|
Or(a=toRAM1, b=toRAM2, out=toRAM);
|
||||||
|
RAM16K(in=in, load=toRAM, address=address[0..13], out=fromRAM);
|
||||||
|
Screen(in=in, load=toScreen, address=address[0..12], out=fromScreen);
|
||||||
|
Keyboard(out=fromKeyboard);
|
||||||
|
|
||||||
|
Mux4Way16(sel=address[13..14], out=out, a=fromRAM,
|
||||||
|
b=fromRAM,
|
||||||
|
c=fromScreen,
|
||||||
|
d=fromKeyboard);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user