Display Memory: Ascii Codes
Display Memory: Ascii Codes
The debugger gives a very close vision of the processor. That is why every program written till now was
executed inside the debugger. Also the debugger is a very useful tool in assembly language program
development, since many bugs only become visible when each instruction is independently monitored
the way the debugger allows us to do. We will now be using the display screen in character mode, the
way DOS uses this screen. The way we will access this screen is specific to the IBM PC.
ASCII CODES
The computer listens, sees, and speaks in numbers. Even a character is a number inside the computer.
For example the keyboard is labeled with characters however when we press ‘A’, a specific number is
transferred from the keyboard to the computer. Our program interprets that number as the character
‘A’. When the same number comes on display, the Video Graphics Adapter (VGA) in our computer shows
the shape of ‘A’. Even the shape is stored in binary numbers with a one bit representing a pixel on the
screen that is turned on and a zero bit representing a pixel that is not glowing. This example is
considering a white on black display and no colors. This is the way a shape is drawn on the screen. The
interpretation of ‘A’ is performed by the VGA card, while the monitor or CRT (cathode ray tube) only
glows the pixels on and turns them off. The keyboard has a key labeled ‘A’ and pressing it the screen
shows ‘A’ but all that happened inside was in numbers.
An ‘A’ on any computer and any operating system is an ‘A’ on every other computer and operating
system. This is because a standard numeric representation of all commonly used characters has been
developed. This is called the ASCII code, where ASCII stands for American Standard Code for Information
Interchange. The name depicts that this is a code that allows the interchange of information; ‘A’ written
on one computer will remain an ‘A’ on another. The ASCII table lists all defined characters and symbols
and their standardized numbers. All ASCII based computers use the same code. There are few other
standards like EBCDIC and gray codes, but ASCII has become the most prevalent standard and is used for
Internet communication as well. It has become the de facto standard for global communication. The
character mode displays of our computer use the ASCII standard. Some newer operating systems use a
new standard Unicode but it is not relevant to us in the current discussion
Standard ASCII has 128 characters with numbers assigned from 0 to 127. When IBM PC was introduced,
they extended the standard ASCII and defined 128 more characters. Thus extending the total number of
symbols from 128 to 256 numbered from 0 to 255 fitting in an 8-bit byte. The newer characters were
used for line drawing, window corners, and some non-English characters. The need for these characters
was never felt on teletype terminals, but with the advent of IBM PC and its full screen display, these
semi-graphics characters were the need of the day. Keep in mind that at that time there was no graphics
mode available.
The extended ASCII code is just a de facto industry standard but it is not defined by an organization like
the standard ASCII. Printers, displays, and all other peripherals related to the IBM PC understand the
ASCII code. If the code for ‘A’ is sent to the printer, the printer will print the shape of ‘A’, if it is sent to
the display, the VGA card will form the shape of ‘A’ on the CRT. If it is sent to another computer via the
serial port, the other computer will understand that this is an ‘A’.
The important thing to observe in the ASCII table is the contiguous arrangement of the uppercase
alphabets (41-5A), the lowercase alphabets (61-7A), and the numbers (30-39). This helps in certain
operations with ASCII, for example converting the case of characters by adding or subtracting 0x20 from
it. It also helps in converting a digit into its ASCII representation by adding 0x30 to it.
We will explore the working of the display with ASCII codes, since it is our immediately accessible
hardware. When 0x40 is sent to the VGA card, it will turn pixels on and off in such a way that a visual
representation of ‘A’ appears on the screen. It has no reality, just an interpretation. In later chapters we
will program the VGA controller to display a new shape when the ASCII of ‘A’ is received by it.
The video device is seen by the computer as a memory area containing the ASCII codes that are
currently displayed on the screen and a set of I/O ports controlling things like the resolution, the cursor
height, and the cursor position. The VGA memory is seen by the computer just like its own memory.
There is no difference; rather the computer doesn’t differentiate, as it is accessible on the same bus as
the system memory. Therefore if that appropriate block of the screen is cleared, the screen will be
cleared. If the ASCII of ‘A’ is placed somewhere in that block, the shape of ‘A’ will appear on the screen
at a corresponding place.
This correspondence must be defined as the memory is a single dimensional space while the screen is
two dimensional having 80 rows and 25 columns. The memory is linearly mapped on this two
dimensional space, just like a two dimensional is mapped in linear memory. There is one word per
character in which a byte is needed for the ASCII code and the other byte is used for the character’s
attributes discussed later. Now the first 80 words will correspond to the first row of the screen and the
next 80 words will correspond to the next row. By making the memory on the video controller accessible
to the processor via the system bus, the processor is now in control of what is displayed on the screen.
The three important things that we discussed are.
• The video controller memory is accessible to the processor like its own memory.
• ASCII code of a character placed at a cell in the VGA memory will cause the corresponding ASCII shape
to be displayed on the corresponding screen location.
The memory at which the video controller’s memory is mapped must be a standard, so that the program
can be written in a video card independent manner. Otherwise if different vendors map their video
memory at different places in the address space, as was the problem in the start, writing software was a
headache. BIOS vendors had a problem of dealing with various card vendors. The IBM PC text mode
color display is now fixed so that system software can work uniformly. It was fixed at the physical
memory location of B8000. The first byte at this location contains the ASCII for the character displayed
at the top left of the video screen. Dropping the zero we can load the rest in a segment register to
access the video memory. If we do something in this memory, the effect can be seen on the screen. For
example we can write a virus that makes any character we write drop to the bottom of the screen.
Attribute Byte
The second byte in the word designated for one screen location holds the foreground and background
colors for the character. This is called its video attribute. So the pair of the ASCII code in one byte and
the attribute in the second byte makes the word that corresponds to one location on the screen. The
lower address contains the code while the higher one contains the attribute. The attribute byte as
detailed below has the RGB for the foreground and the background. It has an intensity bit for the
foreground color as well thus making 16 possible colors of the foreground and 8 possible colors for the
background. When bit 7 is set the character keeps on blinking on the screen. This bit has some more
interpretations like background intensity that has to be activated in the video controller through its I/O
ports.
Display Examples
Both DS and ES can be used to access the video memory. However we commonly keep DS for accessing
our data, and load ES with the segment of video memory. Loading a segment register with an immediate
operand is not allowed in the 8088 architecture. We therefore load the segment register via a general
purpose register. Other methods are loading from a memory location and a combination of push and
pop.
mov es, ax
This operation has opened a window to the video memory. Now the following instruction will print an
‘A’ on the top left of the screen in white color on black background.
The segment override is used since ES is pointing to the video memory. Since the first word is written to,
the character will appear at the top left of the screen. The 41 that goes in the lower byte is the ASCII
code for ‘A’. The 07 that goes in the higher byte is the attribute with I=0, R=1, G=1, B=1 for the
foreground, meaning white color in low intensity and R=0, G=0, B=0 for the background meaning black
color and the most significant bit cleared so that there is no blinking. Now consider the following
instruction.
This is displayed 80 words after the start and there are 80 characters in one screen row. Therefore this is
displayed on the first column of the second line. The ASCII code used is 30, which represents a ‘0’ while
the attribute byte is 12 meaning green color on blue background. We take our first example to clear the
screen.
Example 6.1
Inside the debugger the operation of clearing the screen cannot be observed
since the debugger overwrites whatever is displayed on the screen. Directly executing the COM file from
the command prompt*, we can see that the screen is cleared. The command prompt that reappeared is
printed after the termination of our application. This is the first application that can be directly executed
to see some output on the screen.