0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Nand2Tetris】Memoryチップ アドレス24577~32767へのアクセスを無効にしたい

Last updated at Posted at 2025-08-12

ネタバレ注意

概要

コンピューターシステムの理論と実装をちまちま進めている

第5章のMemoryチップを最初

MemoryチップのHDL その1
CHIP Memory {
    IN in[16], load, address[15];
    OUT out[16];

    PARTS:
    DMux4Way(in=load , sel=address[13..14] , a=do1 , b=do2 , c=do3 , d=do4 );
    Or(a=do1 , b=do2 , out=do12 );
    RAM16K(in=in , load=do12 , address=address[0..13] , out=mo );
    Screen(in=in , load=do3 , address=address[0..12] , out=so );
    Keyboard(out=ko );
    Mux4Way16(a=mo , b=mo , c=so , d=ko , sel=address[13..14] , out=out );
}

のように実装してテストもパスしたけど、これだとアドレス24577~32767へのアクセスでもキーボード入力が出力されてしまう。
しかし、図5-6には

...その他のアドレスにアクセスすることは無効である。

との記載があるので、アドレス24577~32767にアクセスしてもキーボード入力が出力されないようにしたい。

実装

address入力の下位13ビットのORをとって、1ならKeybordチップの出力を0にするという方法で実装した。

MemoryチップのHDL その2
CHIP Memory {
    IN in[16], load, address[15];
    OUT out[16];

    PARTS:
    DMux4Way(in=load , sel=address[13..14] , a=do1 , b=do2 , c=do3 , d=do4 );
    Or(a=do1 , b=do2 , out=do12 );
    RAM16K(in=in , load=do12 , address=address[0..13] , out=mo );
    Screen(in=in , load=do3 , address=address[0..12] , out=so );
    // アドレス制限
    Keyboard(out=ko1 );
    Or8Way(in=address[0..7], out=or1);
    Or8Way(in[0..4]=address[8..12], in[5..7]=false, out=or2);  // 不足ビットは0埋め
    Or(a=or1 , b=or2 , out=anyone );
    Mux16(a=ko1 , b=false , sel=anyone , out=ko2 );  // 全部0ならk01を使い、それ以外は0
    Mux4Way16(a=mo , b=mo , c=so , d=ko2 , sel=address[13..14] , out=out );
}

テストはパスするし、結局後続作業ではビルトインチップを使うのであまり意味はない。
でも気になったので実装できて満足。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?