4.5.输入与输出

\(4.5.\)Input and Output

1. Output

  \(a.\)Display

  • The most important player in manipulating the display element is called screen memory map.
  • It is a designated area which is part of the data memory(RAM).
  • The physical display unit is continuously refreshed from the contents of the memory map, and this happens many times each second. in the next refresh cycle,what is changed in the memory is going to be reflected on the screen.

  \(b.\)Screen memory map

  Our display unit looks like this:

  It's a table, or a matrix, consisting of 256 rows and 512 columns. And in each intersection of a row and a column, we have what is known as a pixel. This is a black and white screen, so we can either turn the pixel on or we can turn it off.

  We can use out screen memory map to manipulate it, which looks like this:

  • It's a sequense of 16-bit values. Each one of these values is called word.

  • For every pixel on the physical display unit, we have a bit that represents this pixel in the screen memory map. If I want to turn on this pixel, I put 1 in this bit, if I want to turn it off,I put 0 in this bit.

  • To set pixel(row, col)on/off:

    1. word = Screen[row*32 + col/16]

      • We cannot access individual bits.If we want to access an individual bit, we have to first figure out in which word this bit resides. And then I have to retrieve the entire word, manipulate this particular bit and finally write it back into memory.
    2. word = RAM[16384 + row*32 + col/16]

      • If we access the screen chip, we simply use \(row\times 32+{col\over 16}\). But if we access the OVERALL RAM, we have to take this relative address and add it to the base address of the memory of the memory map in the overall memory, which happens to be 16384.
    3. Set col%16 bit of word to 0 or 1

    4. Commit word to the RAM

      1. and (4) are done using 16-bit RAM access operations.

2.Input

  \(a.\)Keyboard

  • The physical keyboard is connected to the computer using a cable. If you will trace this cable, you will see that it goes into an area in the RAM which is called keyboard memory map.

  \(b.\)Keyboard memory map

  • Keyboard memory map is a single 16-bit register:

  • When a key is pressed on the keyboard, the key's scan-code, which is an agreed-upon value, travels through the cable and appears in the keyboard memory map.

    • \(e.g.\) If I press 'K', 75 is going to appear in its binary manifestation in the in the keyboard chip.

  • if you want to check if which key is currently pressed, all we have to do is probe the contents of the keyboard chip.

    • In Hack computer, We probe the contents of RAM in address 24576, for this is where the keyboard memory map happens to reside.