Sign in to follow this  
Blue Earthling

How does a computer know to interpret a number stored in a memory location?

Recommended Posts

For example, if I store number 65 in a memory location the computer would display this number as character 'A' using ASCII code tables. But what is this 'table'? Where is it stored? Is it hardware or software?

Share this post


Link to post
Share on other sites
I don't know what is the case for the PC, but it could be both. If it's implemented in software then it's probably done something like this:
- The console (cmd.exe on Windows) stores an array of images (which is each 16x16 bits such that each bit represent whether that pixel is to be painted or not).
- You call a print function with a number (say 65).
- The console recieves this request and writes the image where the cursor currently is.

EDIT: Antheaus just reminded me that they are 80x25 so I re-wrote this section
Each image could be defined as 80x25 (200) bits, so on modern systems it could be written:
// Each char is 8 bits.
typedef char[200/8] image;
image charset[256];


The array could then be filled from some file on disk. It would take up 8KB which isn't significant on modern computers. So it's just stored in the console's memory. Some implementations might use certain optimizations like storing parts of the charset on the disk and loading it on demand. Also if multiple consoles are running they might just access one shared table in some shared memory.

In operating systems without a graphical interface the table is usually stored in the operating systems own memory.

[Edited by - CTar on May 26, 2007 1:48:58 PM]

Share this post


Link to post
Share on other sites
This table stores visual representation of characters.

At most basic level, BIOS (very low level part of any modern computer) contains at least a basic text-mode definition of ASCII characters (how to display them in 80x25 character screen mode). This one is stored in some form of non-volatile memory (one that keeps data after shutdown)

Under graphic OSes, it's much different, since they are represented with fonts. A font serves identical role, but contains considerably more detailed description. These are stored and treated as files, loaded, processed and displayed by the operating system.

Share this post


Link to post
Share on other sites
Quote:
Original post by Blue Earthling
Is it hardware or software?


very simplistically.

There is no "software". Everything that your PC (or any other computer) does has to be done with the hardware. When information is stored it's either in the CPU cache, RAM or the hard drive (or it can be duplicated in all places). Software is simply a string of binary information that controls the CPU (but that information is stored in the hardware).

A memory address as your application sees it is an offset into your application's process space. i.e. it's not a raw address into your RAM, it's an address offset into the space that the OS gave your application to live in. however, with some simple arithmetic that address is converted into a lookup into RAM (where your data "lives").

When information is said to be in memory, it's in RAM. For the CPU to do anything with that information it has to be copied to the CPU cache. And from there it needs to be copied into a CPU register.

And nothing at the hardware level is stored as anything other than binary numbers. The CPU will interpret those binary numbers differently depending on what the software is telling it to do. And the software is working by just plugging a series of binary numbers through the CPU which makes the little electrons travel through different pipes and make different hardware do different things (put colors on your screen, make your speakers vibrate, etc).

That's an insanely basic overview of information that is typically covered in thousand page books. If you're interested in more you should check out one of these books:

Write Great Code: Volume 1
Computer Organization and Design: The Hardware/Software Interface

-me

Share this post


Link to post
Share on other sites
The ASCII code table is a convention.

It is an agreement amount people to say "the number 65 means A in certain contexts".

This code table is implemented in many different ways in many different areas of computing.

Some examples:
In certain graphics modes that are rarely used nowadays, the graphics card uses a ASCII code table (hardware/firmware) that maps the number 65 to the character A.

The URL standard says that %NN represents a character-table lookup of the number NN (ie, %02 is a lookup of the number 02), the bottom 127 values of which line up with ASCII. This is done via software in the browser, or in software on the server.

Fonts are piles of data that map characters to ways to draw them. There are multiple standards for fonts. Programs and OS's interprit the font standard to turn 65 into images of the character A.

...

The thing you have to realize about computers is that they are layers upon layers of abstraction, and that next to nobody understands intimately every single abstraction layer. "Nobody understands how a modern windows computer works", because nobody is an expert capable of understanding all of:
The physics, chemistry and engneering required to make a computer chip.

The chip layout of all of the chips in a modern computer and their interconnections.

The microcode instructions on the chips that take machine language and turn in into instructions for the chip components.

The compilers who map human-written code into machine language.

The reems of code involved in the operation of even the most basic computer operation.

I could give you a vague overview of most of the above, but a human could spend their entire career becoming a true expert at any the above, and still not understand it sufficiently to replicate it.

...

In short, all of the above. :)

Share this post


Link to post
Share on other sites
Here is the simple answer:

There are standards (such as ASCII and Unicode) that determine which letter or symbol each value represents. Computers (or any display device) use a "font" to display text. A font contains the images of each of the characters that can be displayed. The software looks up the image in the font using the numeric value and displays that image. Fonts use these standards, allowing you to switch fonts and still get the same text.

Share this post


Link to post
Share on other sites
The computer itself doesn't know how to interpret a number stored in a memory location. It will interpret it however you tell it to. If you tell it to treat it like a character, then it will treat it like a character (which may eventually involve mapping it the 'A' graphic for display on a screen or printer).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this