0% found this document useful (0 votes)
52 views

Attribute Byte, Display Examples, Printing Hello World

The document describes code to print "Hello World" on the screen using assembly language. It defines a string, clears the screen using a subroutine, and prints the string using another subroutine. The string and its length are passed as parameters to the print subroutine, which uses ES to access video memory and loops through the string writing each character with attributes at the top left of the screen before returning.

Uploaded by

sipra
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Attribute Byte, Display Examples, Printing Hello World

The document describes code to print "Hello World" on the screen using assembly language. It defines a string, clears the screen using a subroutine, and prints the string using another subroutine. The string and its length are passed as parameters to the print subroutine, which uses ES to access video memory and loops through the string writing each character with attributes at the top left of the screen before returning.

Uploaded by

sipra
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Class Presentation

Topic : Attribute Byte, Display examples,


Printing Hello World

Submitted to : Sir Arshad


By: Ehsan Raza

1/11/23 1
Attribute byte:
• One location on the screen is defined by one word made from two bytes i.e., one byte
contains the ASCII code and the second byte in the word holds the foreground and
background colours (attribute) for the character, thus it is called video Attribute or
attribute byte.
• The lower address contains the code while the higher one contains the
• attribute.
Lower byte Higher byte

Ascii code Bl R G B I R G B

1/11/23 3
Attribute byte:
Ascii code Bl R G B I R G B

Background Foreground

• B=BLUE, G=GREEN, R= RED, I=INTENSITY, Bl=BLINK


• RGB bits(3) for foreground: Defines the colour of character(foreground) with eight
different possibilities.
• Intensity bit for foreground: Defines the intensity, i.e., high or low, of the foreground
making eight more possibilities of foreground( total 16 possibilities).
• RGB bits(3) for background: Defines the colour of background with eight different
possibilities.
• Blinking bit: Sets the character to keep on blinking on the screen 1/11/23 3
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. For instance:
mov ax, 0xb800 ; storing value in ax (general purpose reg.)

mov es, ax ; loading segment register

• This operation has opened a window to the video memory.

1/11/23 3
Display Examples:
• Example to print “A” and “0”:

mov ax, 0xb800


mov es, ax

mov word [es:0], 0x0741


;print A at top left
; white fg on black bg

mov word [es:160], 0x1230


;print 0 at second line
;left in green fg on
;blue bg

1/11/23 3
Display Examples:
• Example to Clear screen: 07. The code for space is 20 while 07 is
the normal attribute of low intensity
01 ; clear the screen
white on black with no blinking. Even to
02 [org 0x0100]
clear the screen or put a blank on a
03 mov ax, 0xb800 ; load video base in ax
location there is a numeric code.
04 mov es, ax ; point es to video base
05 mov di, 0 ; point di to top left column
08. DI is incremented twice since each
06
screen location corresponds to two byte
07 nextchar: mov word [es:di], 0x0720 ; clear next char on screen
in video memory.
08 add di, 2 ; move to next screen location
09 cmp di, 4000 ; has the whole screen cleared
09. DI is compared with 80*25*2=4000.
10 jne nextchar ; if no clear next position
The last word location that corresponds
11
to the screen is 3998.
12 mov ax, 0x4c00 ; terminate program
13 int 0x21

• Inside the debugger the operation of clearing the screen cannot be observed since
the debugger overwrites whatever is displayed on the screen. Directly executing 1/11/23 3

the COM file from the command prompt*, we can see that the screen is cleared.
Print “Hello World”
01 ; hello world in assembly
02 [org 0x0100]
03 jmp start 05-06. The string definition syntax
04 discussed above is used to declare a
05 message: db 'hello world' ; string to be printed string “hello world” of 11 bytes and the
06 length: dw 11 ; length of the string length is stored in a separate
07 variable.
08 ; subroutine to clear the screen
09 clrscr: push es 09-25. The code to clear the screen from
10 push ax the last example is written in the form of
11 push di a subroutine. Since the subroutine had no
12 parameters, only modified registers are
13 mov ax, 0xb800 saved and restored from the stack.
14 mov es, ax ; point es to video base
15 mov di, 0 ; point di to top left column
16
17 nextloc: mov word [es:di], 0x0720 ; clear next char on screen
18 add di, 2 ; move to next screen location 1/11/23 3
19 cmp di, 4000 ; has the whole screen cleared
20 jne nextloc ; if no clear next position
Print “Hello World”
21
22 pop di
23 pop ax 29-35. The standard subroutine format
24 pop es with parameters received via stack and
25 ret all registers saved and restored is used.
26
27 ; subroutine to print a string at top left of screen 37-42. ES is initialized to point to the
28 ; takes address of string and its length as parameters video memory via the AX register. Two
29 printstr: push bp pointer registers are used; SI to point to
30 mov bp, sp the string and DI to point to the top left
31 push es location of the screen. CX is loaded with
32 push ax the length of the string. Normal attribute
33 push cx of low intensity white on black with no
34 push si blinking is loaded in the AH register.
35 push di
36
37 mov ax, 0xb800
38 mov es, ax ; point es to video base 1/11/23 3
39 mov di, 0 ; point di to top left column
40 mov si, [bp+6] ; point si to string
Print “Hello World”
44-45. The next character from the string is
41 mov cx, [bp+4] ; load length of string in cx loaded into AL. Now AH holds the attribute
42 mov ah, 0x07 ; normal attribute fixed in al and AL the ASCII code of the character.
43 This pair is written on the video memory
using DI with the segment override prefix
44 nextchar: mov al, [si] ; load next char of string
for ES to access the video memory segment.
45 mov [es:di], ax ; show this char on screen
46 add di, 2 ; move to next screen location 46-47. The string pointer is incremented by
47 add si, 1 ; move to next char in string one while the video memory pointer is
48 loop nextchar ; repeat the operation cx times incremented by two since one char
49 corresponds to a word on the screen.
50 pop di
51 pop si 48. The loop instruction used is equivalent
52 pop cx to a combination of “dec cx” and “jnz
53 pop ax nextchar.” The loop is executed CX times.
54 pop es
55 pop bp 50-56. The registers pushed on the stack are
56 ret 4 recovered in opposite order and the “ret 4”
instruction removes the two parameters
placed on the stack. 1/11/23 3
Print “Hello World”
57
58 start: call clrscr ; call the clrscr subroutine
59 62. Memory can be directly pushed on
60 mov ax, message the stack.
61 push ax ; push address of message
62 push word [length] ; push message length
63 call printstr ; call the printstr subroutine
64
65 mov ax, 0x4c00 ; terminate program
66 int 0x21

1/11/23 3
Now let’s do the Practical

1/11/23 3
THE END

1/11/23 12

You might also like