コンピューター理論、チョットデキルようになりたい

コンピュータサイエンスの学び直しです

学び直し20日目:4章 機械語⑥(4章完了)

記録

IO操作について、、、写経。
github.com

「描画位置の初期化」「押されたかどうか判定して色を設定」「設定された色で範囲をすべて塗りつぶす」みたいな感じだった(はず)。飽きてきちゃったので先に進む。

fill.asm

// 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/04/Fill.asm

// Runs an infinite loop that listens to the keyboard input.
// When a key is pressed (any key), the program blackens the screen,
// i.e. writes "black" in every pixel;
// the screen should remain fully black as long as the key is pressed. 
// When no key is pressed, the program clears the screen, i.e. writes
// "white" in every pixel;
// the screen should remain fully clear as long as no key is pressed.

// Put your code here.
(INIT)
    // Initialize the SCREEN address
    @SCREEN
    D=A
    @addr
    M=D
    // Choice black or white if the key is pressed or not.
    @KBD
    D=M
    // Pressed key -> IFPRESS, not pressed key -> ELSE(wait input)
    @IFPRESS
    D;JGT
    @ELSE
    0;JMP
(IFPRESS)
    @color
    M=-1    // color=-1 -> black
    @ENDIF
    0;JMP
(ELSE)
    @color
    M=0 // color=0 -> white
(ENDIF)
(LOOP)
    // Fill screen
    @color
    D=M
    @addr
    A=M
    M=D // addr <- color
    @addr
    M=M+1

    @8192
    D=A
    @SCREEN
    D=D+A
    @addr
    D=D-M
    @LOOP
    D;JGT

    @INIT
    0;JMP

今日の筋トレ

自宅 B メニューの予定
重量設定 : 5kg