You are on page 1of 16

Faculty Dated: 20/5/2021

Member: Arbab Latif

Semester: 4th Section: BEE-11A

School of Electrical Engineering and Computer Science

EE-222 Microprocessor Systems

Lab8: Real Mode 16-Bit and Graphics Functions


Name Reg. Viva / Quiz / Analysis of Modern Ethics Individual Total
No. Lab data in Lab Tool and and Team
Performance Report usage Safety Work

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks 25 Marks


Noor Tahir 286527

Daniya Imran 321940

Fatima Iqbal 290358


EXPERIMENT 08
REAL MODE 16-BIT AND VIDEO FUNCTIONS
OBJECTIVE:
• In this lab you would perform Video programing using INT10h

EQUIPMENT:
SOFTWARE:
• Turbo Assembler (TASM)

DISCUSSION:
When an application program needs to write characters on the screen in text mode, it can choose
among three types of output:
• MS-DOS-level access: Any computer running or emulating MS-DOS can use INT 21h to write
text to the video display. Input/output can easily be redirected to other devices such as a printer or
disk. Output is quite slow, and you cannot control the text color.
• BIOS-level access: Characters are output using INT 10h function, known as BIOS services. They
execute more quickly than INT 21h and let you specify the text color. When filling large screen
areas, a slight delay can usually be detected. Output cannot be redirected.
• Direct video memory access: Characters are moved directly to video RAM, so execution is
instantaneous. Output cannot be redirected. During the MS-DOS era, word processors and
electronic spreadsheet programs all used this method. (Use of this method is restricted to full-
screen mode under Windows NT, 2000, XP, and beyond.)
In this lab we will be focusing on the BIOS-level access particularly learning to use INT10h for
video/graphics programing.

UNDERSTANDING VIDEO TEXT:


There are two basic video modes on Intel-based systems, text mode and graphics mode. A program
can run in one mode or the other, but not both at the same time:
TEXT MODE:
In text mode, programs write ASCII characters to the screen. The built-in character generator in
the BIOS generates a bit-mapped image for each character. A program cannot draw arbitrary lines
and shapes in text mode.
In text mode, rows are numbered from the top of the screen, row 0. Each row is the height of a
character cell, using the currently active font. Columns are numbered from the left side of the
screen, column 0. Each column is the width of a character cell.
GRAPHICS MODE:
In graphics mode, programs control the appearance of each screen pixel. The operation is
somewhat primitive because there are no built-in functions for line and shape drawing. You can
use built-in functions to write text to the screen in graphics mode, and you can substitute different
fonts for the built-in fonts. MS-Windows provides a collection of functions for drawing shapes
and lines in graphics mode.

ATTRIBUTES:
As illustrated in the following diagrams, each screen character is assigned an attribute byte that
controls both the color of the character (called the foreground) and the screen color behind the
character (called the background) as shown in fig 1.

Figure 1: shows foreground and background.

Each position on the video display holds a single character, along with its own attribute (color).
The attribute is stored in a separate byte, following the character in memory. In the following
figure, three positions on the screen contain the letters ABC:

Figure 2: Shows attribute example of characters ABC.

BLINKING:
Blinking Characters on the video display can blink. The video controller does this by reversing the
foreground and background colors of a character at a predetermined rate. By default, when a PC
boots into MS-DOS mode, blinking is enabled. It is possible to turn blinking off using a video
BIOS function. Also, blinking is off by default when you open up an MS-DOS emulation window
under MS-Windows.
CONTROLLING THE COLOR:
MIXING PRIMARY COLORS:
Each color pixel on a CRT video display is generated using three separate electron beams: red,
green, and blue. A fourth channel controls the overall intensity, or brightness of the pixel. All
available text colors can therefore be represented by 4-bit binary values, in the following form
(I = intensity, R = red, G = green, B = blue). The following diagram shows the composition of a
white pixel:

Figure 3: Shows white pixel in basic color form.

By mixing three primary colors (Table 1), new colors can be generated. Furthermore, by turning
on the intensity bit, you can make the mixed colors brighter.

Table 1: Shows Color mixing examples.

FOUR-BIT COLOR TEXT ENCODING:


ATTRIBUTE BYTE:
In color text mode, each character is assigned an attribute byte, which consists of two 4-bit color
codes: background and foreground as shown in below figure.

Figure 4: Shows attribute byte for background and foreground.


BLINKING (if Enabled)
There is one complication to this simple color scheme. If the video adapter currently has blinking
enabled than the high bit of the background color controls, the character blinking. When this bit is
set, the character blinks. So when blinking is enabled then the intensity bit for background does
not works.

Figure 5:Shows attribute byte for background and foreground for blinking enabled.

From the above attribute byte structure MS-DOS–style primary colors and mixed colors are
compiled into a list of all possible 4-bit colors as shown in Table 2. Each color in the right-hand
column has its intensity bit set.
Table 2: Shows four bit color text encoding.

When blinking is enabled, only the low-intensity colors in the left-hand column of Table 2 are
available as background colors (black, blue, green, cyan, red, magenta, brown, and light gray)
The default color when MS-DOS boots is 00000111 binary (light gray on black background).
INTERUPT 10h VIDEO FUNCTIONS
Table 3 lists the most frequently used INT 10h functions.
Table 3: Shows the functions of INT 10h

Function Function Parameters Return


code
AH = 00h Set video mode AL = video mode AL = video mode flag /
CRT controller mode byte
AH = 01h Set text-mode CH = Scan Row Start, CL = Scan Row End
cursor shape Normally a character cell has 8 scan lines, 0-7. So,
CX=0607h is a normal underline cursor, CX=0007h
is a full-block cursor. If bit 5 of CH is set, that often
means "Hide cursor". So CX=2607h is an invisible
cursor.
AH = 02h Set cursor position BH = Page Number, DH = Row, DL = Column
AH = 03h Get cursor BH = Page Number AX = 0, CH = Start scan
position and shape line, CL = End scan line,
DH = Row, DL = Column
AH = 05h Select active AL = Page Number
display page
AH = 06h Scroll up window AL = lines to scroll (0 = clear, CH, CL, DH, DL
are used),
BH = Background Color and Foreground color. BH
= 43h, means that background color is red and
foreground color is cyan. Refer the BIOS color
attributes

CH = Upper row number, CL = Left column


number, DH = Lower row number, DL = Right
column number
AH = 07h Scroll down like above
window
AH = 08h Read character BH = Page Number AH = Color, AL =
and attribute at Character
cursor position
AH = 09h Write character AL = Character, BH = Page Number, BL = Color,
and attribute at CX = Number of times to print character
cursor position
AH = 0Ah Write character AL = Character, BH = Page Number, CX = Number
only at cursor of times to print character
position
AH = 0Bh Set BL = Background/Border color (border only in text
BH = 00h background/border modes)
color
AH = 0Ch Write graphics AL = Color, BH = Page Number, CX = x, DX = y
pixel
AH = 0Dh Read graphics BH = Page Number, CX = x, DX = y AL = Color
pixel
AH = 0Eh Teletype output AL = Character, BH = Page Number, BL = Color
(only in graphic mode)
AH = 0Fh Get current video AL = Video Mode, AH =
mode number of character
columns, BH = active
page

To set a particular function we need to move that function number into AH register.
INT 10h Function 00h:
Set video mode AH=00h AL = video mode
Following are the video modes that are used in INT 10h
AL = 00h 40x25 B/W text
AL = 01h 40x25 16 color text
AL = 02h 80x25 16 shades of gray text
AL = 03h 80x25 16 color text
AL = 04h, 05h 320x200 4 color graphics
AL = 06h 640x200 B/W graphics
AL = 07h 80x25 Monochrome text
AL = 08h 160x200 16 color graphics
AL = 09h,0Dh,0Eh 320x200 16 color graphics
AL = 0Ah 640x200 4 color graphics
AL = 0Fh 640x350 Monochrome graphics
AL = 10h 640x350 16 color graphics
AL = 11h 640x480 B/W graphics
AL = 12h 640x480 16 color graphics
AL = 13h 320x200 256 color graphics
SAMPLE CODE 1 (SETING VIDEO MODE: FUNCTION 00h)
.model small
.stack 100h
.data
.code
main proc

mov ah,00h ; set the configuration to video mode by using function number
mov al,13h ; choose the video mode 320x200 256 color graphics
int 10h ; executes the configuration

mov ah,4ch
int 21h

main endp
end main
Observe the output in the command window

The Colour of the text on the console is “Brighter” and the resolution/quality is improved.

INT 10h Function 06h:


Scroll up AH = 06h AL = lines to scroll up (0 = clear, CH, CL, DH, DL are used),
window BH = Background Color and Foreground color. BH = 43h, means
that background color is red and foreground color is cyan. Refer the
BIOS color attributes

CH = Upper row number, CL = Left column number, DH = Lower


row number, DL = Right column number
For passing the color value in hexadecimal use following table.
Table 4: Shows color value in Dec and Hex.

SAMPLE CODE 2 (SCROLL WINDOW UP: FUNCTION 06h)


.model small
.stack 100h
.data
.code
main proc

mov ah,6 ; set the configuration to scroll window up by using function number
mov al,10 ; scrolling up by 10 line. If “0” is used then entire window
mov bh, 01000011b ; choosing background “red” and foreground “cyan”
mov ch,5 ; upper left row
mov cl,5 ; upper left column
mov dh,15 ; lower right row
mov dl,15 ; lower right column
int 10h ; executes the configuration

mov ah,4ch
int 21h

main endp
end main
Output:

• A Red background is moved up by 10 lines and 5 units from upper left row and column. The
background is also moved 15 units from lower right row and column
.

INT 10h Function 09h:


Write character and AH = 09h AL = Character, BH = Page Number, BL = Color, CX =
attribute at cursor Number of times to print character
position
For passing the color value in hexadecimal use following table.

Table 5: Shows color value in Dec and Hex.


SAMPLE CODE 3 (WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION:
FUNCTION 09h)
.model small
.stack 100h
.data
.code
main proc

mov ah,09h ; set configuration to write character and attribute at cursor position
mov al,'A' ; moving ASCII of A into al register
mov bh, 0h ; video page 0
mov bl, 71h ; attribute (blue on light gray)
mov cx, 5 ; repetition
int 10h ; executes the configuration

mov ah,4ch
int 21h

main endp
end main

Observe the output in the command window


Answer:

5 Blue ‘A’s are printed in Light gray colour


SAMPLE CODE 4 (WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION
WITH BLINK ENABLED: FUNCTION 09h)
.model small
.stack 100h
.data
.code
main proc

mov ah,09h ; set configuration to write character and attribute at cursor position
mov al,'A' ; moving ASCII of A into al register
mov bh, 0h ; video page 0
mov bl, 11110001b ; attribute (blue on light gray)
mov cx, 5 ; repetition
int 10h ; executes the configuration

mov ah,4ch
int 21h

main endp
end main

Observe the output in the command window

Answer:

5 Blue ‘A’s are printed in Light gray color but Blinking.

What need to be replaced in above code to lower the intensity of the foreground text? Show
your code and result
Answer:
The color of blue is made lighter by the intensity bit.
mov bl,11111001b instruction is added

CODE:
.model small
.stack 100h
.data
.code
main proc
mov ah,09h
mov al,'A'
mov bh, 0h
mov bl,11111001b ;prints blue on light gray color(lower background)
mov cx, 5
int 10h

mov ah,4ch
int 21h

main endp
end main

Output:
EXRERCISES:
1. Write a code to display a graphics as shown below the area of outer most rectangle is
150x250

12

9 3

TASM Code
.model small
.stack 100h
.data
.code

main proc

mov ah,7
mov al,00h
mov bh, 00011111b
mov ch,5
mov cl,0
mov dh,20
mov dl,40
int 10h

mov ah,6
mov al,00h
mov bh, 01110000b
mov ch,7
mov cl,5
mov dh,18
mov dl,35
int 10h

mov ah, 2
mov bh, 0
mov dh, 7
mov dl, 20
int 10h

mov ah, 2
mov dl, '1'
int 21h
mov dl, '2'
int 21h

mov ah, 2
mov bh, 0
mov dh, 12
mov dl, 33
int 10h

mov ah, 2
mov dl, '3'
int 21h

mov ah, 2
mov bh, 0
mov dh, 18
mov dl, 20
int 10h

mov ah, 2
mov dl, '6'
int 21h

mov ah, 2
mov bh, 0
mov dh, 12
mov dl, 7
int 10h

mov ah, 2
mov dl, '9'
int 21h
mov ah, 2
mov bh, 0
mov dh, 2
mov dl, 0
int 10h

mov ah,4ch
int 21h

main endp

end main
Screenshot:

Conclusion:

• In this lab we learned how to change the resolution, make text on the console brighter and
bigger.

• Changing colours of the text using coding commands.

• We learnt the displacement of outputs by units in rows ,coloums left and right.

• Displayed Clock Display using TASM

You might also like