Task: Design and implement an assembly language program using the Hack assembly language that can read input from the keyboard and display it to the simulated screen in the emulated CPU. The program should: Access the RAM address dedicated the keyboard input. Continuously check the keyboard input register for the keystroke. When a key is pressed, read the character.   Create a bitmap image and display the character to the simulated screen.  Upon pressing the Enter key, terminate the program. Requirements: The program should be written in the Hack assembly language. The program should use the nand2tetris tools to run on the emulated CPU. The program should correctly read input from the keyboard and display it to the simulated screen. The program should handle special keys such as Backspace and Enter appropriately. The program should be able to handle multiple simultaneous key presses.  Starting code: // This file is part of www.nand2tetris.org // and the book "The Elements of Computing Systems" // by Nisan and Schocken, MIT Press. // 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. (RESTART) @SCREEN D=A @0 M=D    //PUT SCREEN START LOCATION IN RAM0 /////////////////////////// (KBDCHECK) @KBD D=M @BLACK D;JGT    //JUMP IF ANY KBD KEYS ARE PRESSED @WHITE D;JEQ    //ELSE JUMP TO WHITEN @KBDCHECK 0;JMP /////////////////////////// (BLACK) @1 M=-1    //WHAT TO FILL SCREEN WITH (-1=11111111111111) @CHANGE 0;JMP (WHITE) @1 M=0    //WHAT TO FILL SCREEN WITH @CHANGE 0;JMP ////////////////////////// (CHANGE) @1    //CHECK WHAT TO FILL SCREEN WITH D=M    //D CONTAINS BLACK OR WHITE @0 A=M    //GET ADRESS OF SCREEN PIXEL TO FILL M=D    //FILL IT @0 D=M+1    //INC TO NEXT PIXEL @KBD D=A-D    //KBD-SCREEN=A @0 M=M+1    //INC TO NEXT PIXEL A=M @CHANGE D;JGT    //IF A=0 EXIT AS THE WHOLE SCREEN IS BLACK ///////////////////////// @RESTART 0;JMP

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Task:

Design and implement an assembly language program using the Hack assembly language that can read input from the keyboard and display it to the simulated screen in the emulated CPU. The program should:

  1. Access the RAM address dedicated the keyboard input.
  2. Continuously check the keyboard input register for the keystroke.
  3. When a key is pressed, read the character.  
  4. Create a bitmap image and display the character to the simulated screen. 
  5. Upon pressing the Enter key, terminate the program.

Requirements:

  1. The program should be written in the Hack assembly language.
  2. The program should use the nand2tetris tools to run on the emulated CPU.
  3. The program should correctly read input from the keyboard and display it to the simulated screen.
  4. The program should handle special keys such as Backspace and Enter appropriately.
  5. The program should be able to handle multiple simultaneous key presses. 


    Starting code:

    // This file is part of www.nand2tetris.org
    // and the book "The Elements of Computing Systems"
    // by Nisan and Schocken, MIT Press.

    // 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.
    (RESTART)
    @SCREEN
    D=A
    @0
    M=D    //PUT SCREEN START LOCATION IN RAM0

    ///////////////////////////
    (KBDCHECK)

    @KBD
    D=M
    @BLACK
    D;JGT    //JUMP IF ANY KBD KEYS ARE PRESSED
    @WHITE
    D;JEQ    //ELSE JUMP TO WHITEN

    @KBDCHECK
    0;JMP
    ///////////////////////////
    (BLACK)
    @1
    M=-1    //WHAT TO FILL SCREEN WITH (-1=11111111111111)
    @CHANGE
    0;JMP

    (WHITE)
    @1
    M=0    //WHAT TO FILL SCREEN WITH
    @CHANGE
    0;JMP
    //////////////////////////
    (CHANGE)
    @1    //CHECK WHAT TO FILL SCREEN WITH
    D=M    //D CONTAINS BLACK OR WHITE

    @0
    A=M    //GET ADRESS OF SCREEN PIXEL TO FILL
    M=D    //FILL IT

    @0
    D=M+1    //INC TO NEXT PIXEL
    @KBD
    D=A-D    //KBD-SCREEN=A

    @0
    M=M+1    //INC TO NEXT PIXEL
    A=M

    @CHANGE
    D;JGT    //IF A=0 EXIT AS THE WHOLE SCREEN IS BLACK
    /////////////////////////
    @RESTART
    0;JMP

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Fundamentals of Computer System
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education