Assembly Programming Print Letters (APPL)

If interrupt 21h is generated, what will the computer do? The answer is, there are many possibilities. When interrupt 21h occurs, the first thing the computer does is look at the contents or values ​​contained in the AH register. For example, if the AH value is 2, the computer will print a character, based on the ASCII code contained in the DL register. If the value in the AH register is not 2, when interrupt 21h is performed, the computer will do something different.


Printing Letters With Assembly Language

Thus we can print a desired character by placing the number 2 in the AH register and placing the ASCII code of the character to be printed in the DL register before generating the 21h interrupt.

Program 7.1. Printing a character

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; PROGRAM : A0.ASM ;
; FUNGSI : MENCETAK KARATER ;
; 'A' DENGAN INT 21 ;
;==========================S'to=;
.MODEL SMALL
.CODE
ORG 100h
Proses :
MOV AH,02h ; Nilai servis ntuk mencetak karakter
MOV DL,'A' ; DL = Karakter ASCII yang akan dicetak
INT 21h ; Cetak karakter !!
INT 20h ; Selesai ! kembali ke DOS
END Proses

After program 7.1. you type compile it using TASM.EXE with the command:

C:\>tasm a0
Turbo Assembler Version 2.0 Copyright (c) 1988, 1990
Borland International
Assembling file: a0.ASM
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 306k

C:\>dir a0.*
Volume in drive C is S'to

Directory of C:\
A0 ASM 506 08-14-94 3:56p
A0 OBJ 179 08-14-94 11:24p
2 file(s) 685 bytes

1,267,200 bytes free

Up to this point, an object file from KAL.ASM has been produced which is ready to be made into a COM file (because we created the file with the COM program format). To do that, do the second step, with the command:

C:\>tlink/t a0
Turbo Link Version 3.0 Copyright (c) 1987, 1990
Borland International

C:\>tlink/t a0
Turbo Link Version 3.0 Copyright (c) 1987, 1990
Borland International

C:\>dir a0.*
Volume in drive C is S'to
Directory of C:\
A0 ASM 506 08-14-94 3:56p
A0 OBJ 179 08-14-94 11:26p
A0 MAP 229 08-14-94 11:26p
A0 COM 8 08-14-94 11:26p
4 file(s) 922 bytes

1,266,176 bytes free

After both processes are completed, a COM program is produced that is ready to run. You can delete unused files. When the program 7.1. is run, the screen will display,

C:\>A0
A

We see here that the printed character is the one that corresponds to the ASCII code in the DL register. As an exercise, try changing the DL register to 65, which is the ASCII code for the character 'A'. The results are the same.

Study this function carefully, because we will use it a lot in the following chapters.

Printing Characters and Attributes

A character accompanied by color will certainly be more interesting. For that you can use the 10h interrupt with the rules of use:

INPUT

  • AH = 09h
  • AL = ASCII code of the character to be printed
  • BH = Page number(0 for page 1)
  • BL = Attribute or color of the character to be printed
  • CX = The number of characters to be printed

After all registers have been entered, execute the 10h interrupt. Note that this interrupt prints a character without moving the cursor.

Program 7.2. Printing characters and their attributes

;=================================;
; PROGRAM : A1.ASM ;
; FUNGSI : MENCETAK KARATER 'A';
; BESERTA ATRIBUTNYA ;
; DENGAN INT 10h ;
;============================S'to=;
.MODEL SMALL
.CODE
ORG 100h
Proses :
MOV AH,09h ; Nilai servis untuk mencetak karakter
MOV AL,'A' ; AL = Karakter yang akan dicetak
MOV BH,00h ; Nomor Halaman layar
MOV BL,93h ; Warna atau atribut dari karakter
MOV CX,03h ; Banyaknya karakter yang ingin dicetak
INT 10h ; Laksanakan !!!
INT 20h ; Selesai ! kembali ke DOS
END Proses

When program 7.2. is executed, the letter 'A' will be displayed 3 times with a flashing blue background color and Cyan writing color (according to the BL register value). Regarding the screen page and attributes (colors) we will discuss further in another section.

B:\>A1
AAA

You can change the AL and BL registers to change the characters and colors you want to print.

Repetition with the LOOP Command

The LOOP command is used to perform a repetitive process. The syntax of this command is:

LOOP Tujuan

The goal can be a defined label, for example:

MOV CX,3 ; Banyaknya pengulangan yang dilakukan
Ulang : INT 10h ; Tempat terjadinya pengulangan
LOOP Ulang ; Lompat ke label 'Ulang'

In the looping process with the LOOP command, the CX register plays a special role where this register is used as a counter for the number of loops that may occur. Every time a LOOP command is encountered, the CX register will be reduced by 1 first, then it will be seen whether CX has reached 0. The looping process will be completed when the value in the CX register reaches zero. As in the example above, the 10h interrupt will be generated 3 times (according to the CX value).

Please note that you should not put CX into the LOOP process because this will cause the CX value to be continuously SET so that the looping process cannot stop.

TRICK: If you set the CX value to zero at the first time before the loop is executed, then you will get the most looping processes. This is because the process of subtracting 0 from 1 will produce the value FFFFh(-1),

MOV CX,00
Ulang: LOOP Ulang

Printing Multiple Characters

To print several characters, you can use the looping process. An example of the use of this looping can be seen in program 7.3.

Program 7.3. Repetition with LOOP command

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; PROGRAM : ABC0.ASM ;
; FUNGSI : MENCETAK 16 BUAH ;
; KARAKTER DENGAN ;
; INT 21h SERVIS 02 ;
;==========================S'to=;
.MODEL SMALL
.CODE
ORG 100h
Proses :
MOV AH,02h ; Nilai servis
MOV DL,'A' ; DL=karakter 'A' atau DL=41h
MOV CX,10h ; Banyaknya pengulangan yang akan
Ulang :
INT 21h ; Cetak karakter !!
INC DL ; Tambah DL dengan 1
LOOP Ulang ; Lompat ke Ulang
INT 20h
END Proses

When program 7.3 is run, it will display:

ABCDEFGHIJKLMNOP

The INC DL command will increment the DL register by 1, like the instruction , DL:=DL+1 in Pascal. More about this arithmetic operation (INC) will be discussed in the next chapter.


Post a Comment

Previous Next

نموذج الاتصال