From 87fc2ea2d7ce81d1edd1b2e7e5241c03dad5dbd4 Mon Sep 17 00:00:00 2001 From: Sven Riwoldt Date: Thu, 30 Mar 2023 20:26:18 +0200 Subject: [PATCH] =?UTF-8?q?fertige=20L=C3=B6sung=20zur=20Analyse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/04/tests/hackviaki.asm | 34 +++++++++++++++++++++++ projects/04/tests/hackviaki2.asm | 47 ++++++++++++++++++++++++++++++++ projects/04/tests/loop.asm | 4 +++ 3 files changed, 85 insertions(+) create mode 100644 projects/04/tests/hackviaki.asm create mode 100644 projects/04/tests/hackviaki2.asm diff --git a/projects/04/tests/hackviaki.asm b/projects/04/tests/hackviaki.asm new file mode 100644 index 0000000..38ccedc --- /dev/null +++ b/projects/04/tests/hackviaki.asm @@ -0,0 +1,34 @@ +// Assemblerprogramm zum Zeichnen der mittleren fünf Pixel des HACK-Monitors schwarz + +// Initialisierung der Register +@SCREEN // Adresse des ersten mittleren Pixels +D=A +@R15 // Speicherregister für den Zeiger auf den Bildschirmspeicher +M=D + +// Setzen der Bits für die mittleren fünf Pixel +@5 // Anzahl der zu setzenden Bits +D=A +@R14 // Zähler für die Anzahl der zu setzenden Bits +M=D + +(LOOP) +@R14 +D=M +@END +D;JEQ // Wenn alle Bits gesetzt wurden, Schleife beenden + +@R15 +A=M +M=-1 // Setze das Bit auf 1 (negative Logik für schwarz) + +@R15 +M=M+1 // Zeiger auf das nächste Bit im Speicher erhöhen +@R14 +M=M-1 // Anzahl der zu setzenden Bits reduzieren +@LOOP + +// Programm beendet +(END) +@END +0;JMP diff --git a/projects/04/tests/hackviaki2.asm b/projects/04/tests/hackviaki2.asm new file mode 100644 index 0000000..87b30e8 --- /dev/null +++ b/projects/04/tests/hackviaki2.asm @@ -0,0 +1,47 @@ +// 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. When no key is pressed, the +// program clears the screen, i.e. writes "white" in every pixel. + + +(INIT) //initializes i - index that runs on the screen's pixels + @8192 // 32 * 256 number of 16 bit pixel lines to cover the entire screen + D=A + @i //initializes the index variable to 8192, this is the remaining address left to color onscreen + M=D + +(LOOP) //progresses the index backwards. + @i + M=M-1 + D=M + @INIT + D;JLT //if index<0 - go to INDEX INITIALIZER to reset it + @KBD //loads the keyboard's address + D=M + @WHITE //if (Memory at keyboard address == 0) - meaning no key is pressed - go to WHITE, else go to BLACK + D;JEQ + @BLACK + 0;JMP + +(BLACK) + @SCREEN //loads the screen's first address - 16384 (0x4000) + D=A + @i + A=D+M //adds the current index to the screen's first address in order to color the current set of 16 pixels + M=-1 //sets value in current address to -1, so that the whole word 1...1 (16bits long), meaning - all 16 pixels will be "painted" black. + @LOOP //jumps back to indexer in order to progress the index backwards. + 0;JMP + +(WHITE) + @SCREEN //loads the screen's first address - 16384 (0x4000) + D=A + @i + A=D+M //adds the current index to the screen's first address in order to color the current set of 16 pixels + M=0 //sets value in current address to 0, so that the whole word will be 0....0 (16bits long), meaning - all 16 pixels will be "painted" white. + @LOOP //jumps back to indexer in order to progress the index backwards. + 0;JMP \ No newline at end of file diff --git a/projects/04/tests/loop.asm b/projects/04/tests/loop.asm index 5fd0099..70f2818 100644 --- a/projects/04/tests/loop.asm +++ b/projects/04/tests/loop.asm @@ -15,4 +15,8 @@ M=D (LOOP) @actpos D=M +@SCREEN +D=D+M +M=D +MD=M-1 @endpos