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

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter11: Operating Systems
Section: Chapter Questions
Problem 29VE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning