12

So the question is: How does a computer go from binary code representing the letter "g" to the correct combination of pixel illuminations?

Here is what I have managed to figure out so far. I understand how the CPU takes the input generated by the keyboard and stores it in the RAM, and then retrieves it to do operations on using an instruction set. I also understand how it does these operations in detail. Then the CPU transmits the output of an operation which for this example is an instruction set that retrieves the "g" from the memory address and sends it to the monitor output.

Now my question is does the CPU convert the letter "g" to a bitmap directly or does it use a GPU that is either built-in or separate, OR does the monitor itself handle the conversion?

Also, is it possible to write your own code that interprets the binary and formats it for display?

Jean-Luc Thumm
  • 145
  • 1
  • 1
  • 4
  • Which O.S.? Does it have a GUI or does it use the console? – Tarik Aug 12 '13 at 06:24
  • I am not talking about a specific case, I was asking generally. Either way all OSs and GUIs boil down to machine code and binary. I am simply asking how that gets converted to what I see and by what hardware – Jean-Luc Thumm Aug 12 '13 at 06:25
  • Well, depending on the O.S. things are done differently, so there is no general answer. It would be lengthy to describe the mechanism used by each and every O.S. – Tarik Aug 12 '13 at 06:41
  • i got this doubt exactly after 7 years 7 months after this question is posted,@Jean-LucThumm thanks for asking this because of you i got ready made answer – Aviroxi Mar 18 '21 at 19:18

2 Answers2

12

In most systems the CPU doesn't speak with the monitor directly; it sends commands to a graphics card which in turn generates an electric signal that the monitor translates into a picture on the screen. There are many steps in this process and the processing model is system dependent.

From the software perspective, communication with the graphics card is made through a graphics card driver that translates your program's and the operating system's requests into something that the hardware on the card can understand.

There are different kinds of drivers; the simplest to explain is a text mode driver. In text mode the screen is composed of a number of cells, each of which can hold exactly one of predefined characters. The driver includes a predefined bit map font that describes how a character looks like by specifying which pixels are on and which are off . When a program requests a character to be printed on the screen, the driver looks it up in the font and tells the card to change the electric signal it's sending to the monitor so that the pixels on the screen reflect what's in the font.

The text mode has limited use though. You get only one choice of font, a limited choice of colors, and you can't draw graphics like lines or circles: you're limited to characters. For high quality graphics output a different driver is used. Graphics cards typically include a memory buffer that contains the contents of the screen in a well defined format, like "n bits per pixel, m pixels per row, .." To draw something on the screen you just have to write to this memory buffer. In order to do that the driver maps the buffer into the computer memory so that the operating system and programs can use the buffer as if it was a part of RAM. Programs then can directly put the pixels they want to show, and to put the letter g on the screen it's up to the application programmer to output pixels in a way that resembles that letter. Of course there are many libraries to help programmers do this, otherwise the current state of the graphical user interface would be even sorrier than it is.

Of course, this is a simplification of what actually goes on in a computer, and there are systems that don't work exactly like this, for example some CPUs do have an integrated graphics card, and some output devices are not based on drawing pixels but plotting lines, but I hope this clears the confusion a little.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • And how would one go about writing one of these basic text driver for a command line OS? Also what type of language is used for these drivers? Assembly? Machine? High-level? – Jean-Luc Thumm Aug 12 '13 at 20:34
  • That would depend on the video hardware available and the OS, see for example http://en.wikipedia.org/wiki/Text_mode. On Unix and Windows most device drivers are often written in C with some inline assembly thrown in where necessary. – Joni Aug 12 '13 at 21:17
3

See here http://en.m.wikipedia.org/wiki/Code_page_437 It describes the character based mechanism used to display characters on a VGA monitor in character mode.

Tarik
  • 10,810
  • 2
  • 26
  • 40