Question

In: Computer Science

I didn't know , how to write this code // This file is part of www.nand2tetris.org...

I didn't know , how to write this code

// 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.

Solutions

Expert Solution

fill.asm

(INIT)    //initializing i - index that runs on the screen's pixels
        @8192    // 32 * 256 number of 16 bit pixel lines it covers the entire screen
        D=A
        @i                   //initializing 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)it means that 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

NOTE: There are various ways to solve this question I'm providing you with one detailed steps of it. If in case you face any error please do let me know through comments.

UPVOTE!!!!Please... Thank You!!!


Related Solutions

It shows me that 1 error exists in this code but I didn't know how to...
It shows me that 1 error exists in this code but I didn't know how to fix this error so if you can help I will appreciate it. Language C++. Code: #include <iostream> #include <string> #include <iterator> #include <fstream> #include <sstream> #include <cstdlib> #include <set> using namespace std; class Book { private: string BookId; string BookISBN; string Publisher; int PublisherYear; double Price; int Quantity; string Author; public: string SetBookId(); string SetBookISBN(); string SetPublisher(); int SetPublisherYear(); double SetPrice(); int SetQuantity(); string...
There is no data associated with these questions, they are just general questions. I didn't know...
There is no data associated with these questions, they are just general questions. I didn't know what is the difference between them. a. What does the population distribution count? b. What does the sample distribution count? c. What does the distribution of sample means count?
this is my Matlab code for lemur and plant population simulation. But i didn't get the...
this is my Matlab code for lemur and plant population simulation. But i didn't get the right graph. R(1,1)=35; % Initial pop of males R(2,1)=35; % Initial pop of females P(3,1)=200000; % Iniitial pop of plants r(1)=1.01; % Growth rate of male pop r(2)=1.01; % Growth rate of female pop r(3)=1.10; % Growth rate of plants K(1)=800; % Carrying capacity for male pop K(2)=600; % carrying capacity for female pop K(3)=7500000; % carrying capacity for plants    E=65; % Plants...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
I need to write a resume and I do not know how to write it. Please...
I need to write a resume and I do not know how to write it. Please help me. My name is John Doe. I finished Associate of Science in (Electrical Engineering, Computer Engineering, Physics and Math) from Community College. I have work experience over 10 years at food company. Please help me write as completely as possible. Thanks a lot for your help!
Part 1. Single-tone Modulation a –Write the code for an m-file (script) to generate a single...
Part 1. Single-tone Modulation a –Write the code for an m-file (script) to generate a single tone FM signal. The modulating (message) signal is a single tone signal with frequency 1kHz and the carrier frequency is 20kHz. Vary the modulation index as m=0.2; 0.5; 1; 5 and 10. Plot your original message signal and the modulated signal for each value of m. Discuss the results. Use cosine function to define the message signal. b- Repeat the part above only that...
I already have the code of this program, I just want to know how to fix...
I already have the code of this program, I just want to know how to fix the code to Implement the 5th function (System.nanotime() and System.currentTimeMillis() methods) What Code does: Introduction Searching is a fundamental operation of computer applications and can be performed using either the inefficient linear search algorithm with a time complexity of O (n) or by using the more efficient binary search algorithm with a time complexity of O (log n). Task Requirements In this lab, you...
COMPUTER CALCULATIONS: I need to know how to code in R for the solutions, not by...
COMPUTER CALCULATIONS: I need to know how to code in R for the solutions, not by hand. 2. Look at the data in Table 7.18 on page 368 of the textbook. These data are also given in the SAS code labeled “SAS_basketball_goal_data” and R code labeled basketball goal data . The dependent variable is goals and the independent variable is height of basketball players. Complete a SAS /R program and answer the following questions about the data set: (a) Does...
Below is my source code for file merging. when i run the code my merged file...
Below is my source code for file merging. when i run the code my merged file is blank and it never shows merging complete prompt. i dont see any errors or why my code would be causing this. i saved both files with male names and female names in the same location my source code is in as a rtf #include #include #include using namespace std; int main() { ifstream inFile1; ifstream inFile2; ofstream outFile1; int mClientNumber, fClientNumber; string mClientName;...
I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT