fertige Lösung zur Analyse
This commit is contained in:
34
projects/04/tests/hackviaki.asm
Normal file
34
projects/04/tests/hackviaki.asm
Normal file
@@ -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
|
||||
47
projects/04/tests/hackviaki2.asm
Normal file
47
projects/04/tests/hackviaki2.asm
Normal file
@@ -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
|
||||
@@ -15,4 +15,8 @@ M=D
|
||||
(LOOP)
|
||||
@actpos
|
||||
D=M
|
||||
@SCREEN
|
||||
D=D+M
|
||||
M=D
|
||||
MD=M-1
|
||||
@endpos
|
||||
|
||||
Reference in New Issue
Block a user