You are on page 1of 132

ASSEMBLY LANGUAGE- TASM

LABORATORY MANUAL for
CC ELEC 3218 S1
ASSEMBLY LANGUAGE

MELJUN P. CORTES
________________________________

CS ELEC 3218 S1
Computer Organization with
Assembly Language Programming
_______________________________

IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR
THE DEGREE OF BACHELOR OF SCIENCE IN COMPUTER SCIENCE (BSCS)

________________________________

MELJUN P. CORTES, MBA,MPA,BSCS,ACS

DECEMBER 2005 HANDOUTS

ASSEMBLY LANGUAGE
TABLE OF CONTENTS

I. BASIC USAGE...............................................................................................................................4

A. Tools of the Trades............................................................................................................4

B. Step on using Turbo Assembler.......................................................................................5

C. The MS-DOS Editor.........................................................................................................7

1. The Interface and Menus......................................................................................7

2. Basic Copy-Pasting Commands............................................................................9

3. Exercise.................................................................................................................10

II. OUR FIRST PROGRAM...........................................................................................................14

A. Activity 1..........................................................................................................................14

B. Compiling and Running the File....................................................................................15

C. Analysis of the Program.................................................................................................16

1. Comments and Heading......................................................................................16

2. MODEL and CODE............................................................................................16

3. Labels, Jumps, and Define Bytes........................................................................17

4. Move, Registers, Interrupts, and Clear Screen (CLRSCR).............................18

5. Positioning the Character (GOTOXY)..............................................................19

6. Printing some strings (PRINTF).........................................................................19

7. Terminate COM File, End Main, End...............................................................20

D. Activity 2..........................................................................................................................20

2
III. MP1: INPUT AND OUTPUT....................................................................................................6

A. ASCII Characters...........................................................................................................46

B. Accepting Some Strings (SCANF).................................................................................46

IV. MP2: TEXT, SOUNDS, AND GRAPHICS!...........................................................................49

A. Macros..............................................................................................................................96

B. CMP, JMP Commands.................................................................................................103

C. Get Keystrokes (GETCH)............................................................................................103

D. PUSH & POP.................................................................................................................104

E. EQU Command.............................................................................................................104

F. Colored & Blinking Text (CPRINTF).........................................................................105

G. Sounds............................................................................................................................108

H. Graphics.........................................................................................................................109

IV. PEX: A CLOSER LOOK AT DB..........................................................................................111

V. MP3: ASCII CODE HANDLING...........................................................................................113

VI. MORE EXAMPLES: MEMORY HANDLING...................................................................119

A. Exercise 1.......................................................................................................................119

B. Exercise 2.......................................................................................................................121

C. Exercise 3.......................................................................................................................124

D. Exercise 4.......................................................................................................................127

E. Exercise 5.......................................................................................................................129

F. Exercise 6........................................................................................................................132

3
PERSONAL NOTES FROM THE AUTHORS

4
I. BASIC USAGE

We‟ll be using Borland Turbo Assembler 2.0 and MS-DOS Edit on DOS mode. Actually, you can work

in Windows Mode, but for more usability (and also for a feel of the “old traditional way”), I recommend

using DOS mode.

A. Tools of the Trades

On using Turbo Assembler, we need these things:

Text Editor – These are pure text only. You cannot use any formatting like Bold, Italic, or whatever, just

purely text. Examples of these are Notepad, and the Windows Edit. NOTE: Actually you can use

Microsoft Word; just use it in the appropriate manner. If you don‟t have it (rarely it does), you can

download other DOS Text Editors at: http://www.eunet.bg/simtel.net/msdos/editor-pre.html

Compiler – This is where we will compile our source code into object code (COM or EXE). If you don‟t

have it, I‟ve found a site for it: http://www.nanadata.com/download/assembly.htm

NOTE: About the debugger, actually, you can have a debugger, to save time from debugging. There are

many good debuggers out there, but you could use TD.EXE that is bundled with the Assembler Program.

About the downloaded programs, the program interface may vary from program to program, but the

commands and principles are still the same. About installing, usually these programs don‟t need

5
installing (or maybe sometimes just “unzipping”), but I recommend putting these programs not too deep

in the directory for easy accessing.

B. Steps on Using Turbo Assembler

Step 1: Go To DOS Mode

First thing that we should know, probably you‟re using Windows Mode, now we need to go to the

same old DOS mode.

a. Referring to the default desktop them of the windows, on the bottom left of the screen, click the

Start button.

b. Then point to All Programs.

c. Then point to Accessories.

d. Then click Command Prompt. Then a console program called MS-DOS will now open.

NOTE: If not in full screen, you can press ALT-ENTER to toggle to full screen.

Step 2: Change Drive to the Assembler

Usually you only have one drive, so you could skip this. But if you have a dual drive (or more)

and the assembler is not on your current drive (or system drive), try using Change Drive Dos

Commands, here‟s the syntax:

[drive]:

Where you [drive] is where you want to go. For example, if your in drive D: and your assembler is

in drive C: type:

C:

6
Step 3: Change Directory to the Assembler

Ok, now we need to go to that assembler directory. Now we need to go to it using the CD DOS

command. The CD means “change directory”, and the syntax is:

CD [directory]

Where the [directory] is where you want to go. For example, if your assembler is in C:\TASM,

type:

CD\TASM

Step 4: Open a Text Editor

Ok, you‟re on the Turbo Assembler directory, what‟s next? Now, we need to open a Text Editor

program. Usually the operating system provides for it like the MS-DOS Editor, to open it type:

EDIT

NOTE: You might notice that the EDIT.COM might not be present at the directory, but actually

you called it from another directory through the help of PATH environment variable.

7
C. The MS-DOS Editor

1. The Interface and Menus

The first thing that we should know is to familiarize with the MS-DOS Edit Interface and here are

the parts:

Menu Bar – Here are the list of commands.

Title Bar – Here is where the name of the file is.

Workspace – Here is where you type.

Status bar – Here provides some useful info about the menu and also the location of your cursor.

And also, here are the list of the menus you can use:
MENUS.TXT

File

New

Open...

Save

Save As...

Close

Print...

Exit

Edit

Cut Ctrl+X

Copy Ctrl+C

Paste Ctrl+V

Clear Del

Search

Find...

Repeat Last Find F3

Replace...

8
View

Split Window Ctrl+F6

Size Window Ctrl+F8

Close Window Ctrl+F4

Options

Settings...

Tab Stops

Printer Port

Colors...

Item

Foreground

Background

Help

Commands...

About...

2. Basic Copy-Pasting Commands

Copy-pasting on MS-DOS is very much the same on other Word Processors like:

Cut – CTRL + X

Copy – CTRL + C

Paste – CTRL + V

To make this possible, first you must need to highlight them. Highlighting specifies the part where

you want to manipulate.

9
To highlight:

Step 1: Position your cursor to the first text you want to manipulate

Step 2: Hold SHIFT key, then move your cursor to the last text you want to manipulate. Then

release the SHIFT key.

Then, go to the part where you want to move (cut) or make a duplicate (copy) it, by pressing the

right codes.

3. Exercise

Type this first on your workspace:
1.ASM

Remember that the layout should be as is: Centered. Then Save As it as file 1.ASM. Then copy

everything, then create a New file, then paste it, then put TWO on top of it, then Save As it as file

2.ASM, then so on and so fourth until 5.ASM. NOTE: You might be curious how could you paste

it to a new workspace when you closed the previous workspace. It is because when you cut or

copy it, it will be saved in the buffer (or memory) then when you paste it, it will be reclaimed

again.

Now this should every file looks like:
2.ASM

3.ASM

4.ASM

5.ASM

10
II. OUR FIRST PROGRAM

Ok, enough with the basic stuffs and let‟s go to the actual coding. Now, let‟s make our first program!

Yippee!

A. Activity 1

We will not make our first program to be a traditional HELLO WORLD program, but rather we will

make a program that would output, “Assembly Language”. On the workspace, type this:

(VERBATIMLY)

ACTV1.ASM

; FILENAME : ACTV1.ASM

; PROGRAMMED BY : MELJUN P. CORTES.

; DATE STARTED : SEPT. 22, 2005

; DATE FINISHED : ----------------------

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

STR1 DB "ASSEMBLY LANGUAGE$"

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

MOV BH, 0

MOV DH, 12

11
MOV DL, 30

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

INT 20H

END MAIN

END

Then Save As it as ACTV1.ASM.

B. Compiling and Running the File

On the command prompt (or DOS mode), these are the steps

Step 1: Type: “TASM ACTV1.ASM” – This checks if there are error, if none, then creates an

object file.

Step 2: Type: “TLINK ACTV1.OBJ /T” – This creates an executable file. The parameter “/T”

means create a COM file.

Step 3: Type: “ACTV1.COM” – This executes the file.

NOTE: Actually, you can omit the extensions; I‟ve just included it to make it clear.

Now after you run it (or execute it), you will see the “Assembly Language” was outputted at almost at the

middle of the screen.

12
C. Analysis of the Program

Ok after running the program, let‟s now understand how it was made. I‟ll explain it block-per-block or

line-per-line:

1. Comments and Heading

; FILENAME : ACTV1.ASM

; PROGRAMMED BY : MELJUN P. CORTES

; DATE STARTED : SEPT. 22, 2005

; DATE FINISHED : ----------------------

This is just a heading. Actually it can be removed from the code and will not affect anything, but

this is substantial on making a program for quick info. Noticed that they all start with a “;”, that

means it is a comment. A comment starts after the semicolon. The compiler always omits it. It

helps the programmers to easily (and neatly) code the program. As a suggestion also, always put

comments on your programs make your codes organized and neat it will help you greatly on

debugging and others too who is debugging your program.

2. MODEL and CODE

.MODEL TINY

13
This tells the compiler you‟re just making a tiny (small) program.

.CODE

ORG 0100H

This tells the compiler to load the program at memory location 100H. The „H‟ means it is in

Hexadecimal form. And actually, all programs should load after the 100H memory located,

because important stuff are stored in 0-100H memory location like Interrupt Vector Table.

3. Labels, Jumps, and Define Bytes

MAIN: JMP START

STR1 DB "ASSEMBLY LANGUAGE$"

START:

The “MAIN:” means it‟s a label, meaning it can loop or jump to the code again. Just like

“START:”, “JMP START”, JMP means Jump, this means it will jump to label START. The

“STR1 DB “ASSEMBLY LANGUAGE”” means it will defined “ASSEMBLY LANGUAGE” as

STR1, the DB means Define Byte. You might ask, “Why not Define Word?” It is because the

compiler defines every character not series of character and every letter have corresponding byte.

NOTE: You might ask, “Will the “STR1 DB “ASSEMBLY LANGUAGE”” work? Because it

was skipped”, actually, it will still work because the phrase “ASSEMBLY LANGUAGE” will be

also loaded into the memory, that is because when you load a COM file, everything in that COM

14
file will be loaded into the memory. Phew! Very Complicated! And actually I hate complicated

things! But this is Assembly, Welcome to the Assembly World! =)

4. Move, Registers, Interrupts, and Clear Screen (CLRSCR)

MOV AX, 03H

INT 10H

Ok, let‟s study some new stuff here. The processor has some memories in it but it is not called

memories but rather registers like: AX, BX, CX, and DX. And each of them has a lower and

higher byte. For example AX, has a lower byte (AL) and a higher byte (AH), and BX has a lower

byte (BL) and a higher byte (BH) and so on and so forth. In the line, “MOV AX, 03H” actually

the command MOV, is quit inaccurate, it doesn‟t move thing but rather copy things, this is the

syntax:

MOV [destination], [source]

In that line, it tells the compiler to input value 03H into register AX. Why 03H? I‟ll explain later.

In the line “INT 10H” it calls an interrupt 10H and the function would depend on the number of

the AX. Interrupt 10H and the register AX that contains 03H calls a function that clears the

screen. For more information about Interrupts, check Ralph Brown‟s Interrupt Lists on the

Internet.

5. Positioning the Character (GOTOXY)

15
MOV AH, 02H

MOV DH, 12

MOV DL, 30

INT 10H

This code tells the computer to position the cursor at column 30, row 12. So the syntax for this is:

MOV AH, 02H

MOV DH, [ROW]

MOV DL, [COLUMN]

INT 10H

6. Printing some strings (PRINTF)

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

The “OFFSET STR1” means get the memory location of STR1. The function INT 21H/AX=09H

do, is that it will print everything starting from the memory location stated at the DX until it

encountered „$‟.

7. Terminate COM File, End Main, End

16
INT 20H

END MAIN

END

The “INT 20H” (actually it doesn‟t anymore AX value) calls a function that terminate the current

COM file program. The “END MAIN” means end the MAIN procedure and the “END” tells the

compiler it is the end of the whole source code.

Phew! So many things to remember! Just relax, soon you‟ll get used to it. Now, just take time to

digest everything that we‟ve studied for today.

D. Activity 2

Study? Ok, now, using the source code from the first activity, let‟s try to output multiple line, lets output

our first exercise, type this:

ACTV2.ASM

; FILENAME : ACTV2.ASM

; PROGRAMMED BY : MELJUN P. CORTES .

; DATE STARTED : SEPT. 22, 2005

; DATE FINISHED : ----------------------

.MODEL TINY

.CODE

ORG 0100H

17
MAIN: JMP START

STR1 DB "ASSEMBLY LANGUAGE$"

STR2 DB " AMA$"

STR3 DB " COMPUTER UNIVERSITY$"

STR4 DB " VILLA ARCA STREET. PROJECT 08, QUEZON CITY$"

STR5 DB " CSCI06CA$"

STR6 DB " COMPUTER ORGANIZATION ARCHITECTURE & ASSEMBLY LANGUAGE PROGRAMMING$"

STR7 DB " MELJUN P. CORTES, MBA,MPA,BSCS,ACS .$"

STR8 DB " STUDENT$"

STR9 DB " MELJUN P. CORTES $"

STR10 DB " INSTRUCTOR$"

STR11 DB " SEPTEMBER 15, 2005$"

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

MOV BH, 0

MOV DH, 1

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 2

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR2

18
INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 3

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR3

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 4

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR4

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 5

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR5

INT 21H

MOV AH, 02H

19
MOV BH, 0

MOV DH, 6

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR6

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 7

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR7

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 8

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR8

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 9

MOV DL, 1

20
INT 10H

MOV AH, 09H

MOV DX, OFFSET STR9

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 10

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR10

INT 21H

MOV AH, 02H

MOV BH, 0

MOV DH, 11

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR11

INT 21H

INT 20H

END MAIN

END

21
Notice I‟ve just used GOTOXY function to print multiple lines, and this how Assembly works!

Instruction-Per-Instruction, unlike other languages that are shortcut. And congratulations! You‟ve made a

full pledge program that displays a full screen output!

These are the basics and principles of assembly. After learning these basics, on our next learning would

be easier.

22
III. MP1: INPUT AND OUTPUT

Now that you learned how to output (PRINTF) things, we will just now concentrate on inputting

(SCANF) things. Our first MP was to make a Slum Book program that would accept strings. I‟ll post my

source code here for you to have a better view:

PMCMP1.ASM

; FILENAME : PMCMP1.ASM

; PROGRAMMED BY : MELJUN P. CORTES

; DATE STARTED : SEPTEMBER 29, 2005

; DATE FINISHED : ______________________

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START ; THIS IS THE MIDDLE

SPLA DB " °°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°° $"

SPLB DB "°°±±±±±±±±°±±±±±° °±±±±±±±±±°±±±±±±±±±° $"

SPLC DB "°±± ±°± ±° °± ± ±°± ±° $"

SPLD DB "°± ÛÛÛÛ ±°± Û ±° °± Û ± Û ±°± Û Û ±° $"

SPLE DB "°± Û ±°± Û ±°°°°± Û ± Û ±°± ÛÛ ÛÛ ±° CREATED BY: $"

SPLF DB "°± ÛÛÛ ±°± Û ±±±±°± Û ± Û ±°± Û Û Û ±° MELJUN P. CORTES . $"

SPLG DB "°± Û ±°± Û ±°± Û Û ±°± Û Û Û ±° $"

SPLH DB "°± ÛÛÛÛ ±°± ÛÛÛÛ ±°± ÛÛÛ ±°± Û Û Û ±° $"

SPLI DB "°± ±±°± ±°±± ±±°± ±° $"

SPLJ DB "°±±±±±±±±°°±±±±±±±±°°±±±±±±±°°±±±±±±±±±° $"

SPLK DB "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° $"

SPLL DB " °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°$"

SPLM DB " °±±±±±±±±°°°±±±±±±±°°°±±±±±±±°°±±±±±±±±±°$"

23
SPLN DB " °± ±±°±± ±±°±± ±±°± ± ±°$"

SPLO DB " °± ÛÛÛÛ ±°± ÛÛÛ ±°± ÛÛÛ ±°± Û Û ±°$"

SPLP DB " PRESS ENTER °± Û Û ±°± Û Û ±°± Û Û ±°± Û Û ±°$"

SPLQ DB " TO CONTINUE... °± ÛÛÛÛ ±°± Û Û ±°± Û Û ±°± ÛÛÛ ±±°$"

SPLR DB " °± Û Û ±°± Û Û ±°± Û Û ±°± Û Û ±°$"

SPLS DB " °± ÛÛÛÛ ±°± ÛÛÛ ±°± ÛÛÛ ±°± Û Û ±°$"

SPLT DB " °± ±±°±± ±±°±± ±±°± ± ±°$"

SPLU DB " °±±±±±±±±°°°±±±±±±±°°°±±±±±±±°°±±±±±±±±±°$"

SPLV DB " °°°°°°°°°° °°°°°°°°° °°°°°°°°°°°°°°°°°°°°$"

STRA DB "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ$"

STRB DB "±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±$"

STRC DB "±±±±±±±±±ÛÛÛÛ±±Û±±±±±±Û±±±Û±±Û±±±Û±±±±±±±±ÛÛÛÛ±±±±ÛÛÛ±±±±ÛÛÛ±±±Û±±±Û±±±±±±±±±±$"

STRD DB "±±±±±±±±Û±±±±±±Û±±±±±±Û±±±Û±±ÛÛ±ÛÛ±±±±±±±±Û±±±Û±±Û±±±Û±±Û±±±Û±±Û±±Û±±±±±±±±±±±$"

STRE DB "±±±±±±±±±ÛÛÛ±±±Û±±±±±±Û±±±Û±±Û±Û±Û±±±±±±±±ÛÛÛÛ±±±Û±±±Û±±Û±±±Û±±ÛÛÛ±±±±±±±±±±±±$"

STRF DB "±±±±±±±±±±±±Û±±Û±±±±±±Û±±±Û±±Û±Û±Û±±±±±±±±Û±±±Û±±Û±±±Û±±Û±±±Û±±Û±±Û±±±±±±±±±±±$"

STRG DB "±±±±±±±±ÛÛÛÛ±±±ÛÛÛÛÛ±±±ÛÛÛ±±±Û±Û±Û±±±±±±±±ÛÛÛÛ±±±±ÛÛÛ±±±±ÛÛÛ±±±Û±±±Û±±±±±±±±±±$"

STRH DB "±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±$"

STRI DB "±±±±±±±ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍGENERAL INFORMATIONÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»±±±±±±±±$"

STRJ DB "±±±±±±±º NAME : NICKNAME : º±±±±±±±±$"

STRK DB "±±±±±±±º TEL. NO. : ( ) - º±±±±±±±±$"

STRL DB "±±±±±±±º ADDRESS : º±±±±±±±±$"

STRM DB "±±±±±±±º BIRTHDAY : AGE : º±±±±±±±±$"

STRN DB "±±±±±±±ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍPERSONAL INFORMATIONÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹±±±±±±±±$"

STRO DB "±±±±±±±º WHAT ARE YOU FAVORITE COLORS: (AT LEAST 8) º±±±±±±±±$"

STRP DB "±±±±±±±º 1. º±±±±±±±±$"

STRQ DB "±±±±±±±º 2. º±±±±±±±±$"

STRR DB "±±±±±±±º 3. º±±±±±±±±$"

STRS DB "±±±±±±±º WHO IS YOUR FAVORITE ACTOR / ACTRESS º±±±±±±±±$"

STRT DB "±±±±±±±º 1. º±±±±±±±±$"

STRU DB "±±±±±±±º 2. º±±±±±±±±$"

STRV DB "±±±±±±±º MOTTO: º±±±±±±±±$"

STRW DB "±±±±±±±ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ±±±±±±±±$"

STRX DB "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ$"

ATWO DB 15,?,14 DUP (?)

AONE DB 15,?,14 DUP (?)

24
CTHREE DB 15,?,14 DUP (?)

CTWO DB 15,?,14 DUP (?)

CONE DB 15,?,14 DUP (?)

HNAME DB 23,?,22 DUP (?)

NICKNAME DB 14,?,13 DUP (?)

HADDRESS DB 48,?,47 DUP (?)

NUMBER DB 5,?,4 DUP (?)

COMPANY DB 4,?,3 DUP (?)

LOCALAREA DB 3,?,2 DUP (?)

BIRTHDAY DB 15,?,14 DUP (?)

AGE DB 4,?,3 DUP (?)

MOTTO DB 52,?,51 DUP (?)

TESTING DB 2,?,1 DUP (?)

START:

; ================ SPLASH OUTPUT ================

; ================ CLEARS THE SCREEN

MOV AX, 03H

INT 10H

; ================ LINE 1

MOV AH, 02H

MOV DH, 1

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLA

INT 21H

; ================ LINE 2

MOV AH, 02H

MOV DH, 2

MOV DL, 1

INT 10H

25
MOV AH, 09H

MOV DX, OFFSET SPLB

INT 21H

; ================ LINE 3

MOV AH, 02H

MOV DH, 3

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLC

INT 21H

; ================ LINE 4

MOV AH, 02H

MOV DH, 4

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLD

INT 21H

; ================ LINE 5

MOV AH, 02H

MOV DH, 5

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLE

INT 21H

; ================ LINE 6

MOV AH, 02H

26
MOV DH, 6

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLF

INT 21H

; ================ LINE 7

MOV AH, 02H

MOV DH, 7

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLG

INT 21H

; ================ LINE 8

MOV AH, 02H

MOV DH, 8

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLH

INT 21H

; ================ LINE 9

MOV AH, 02H

MOV DH, 9

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLI

27
INT 21H

; ================ LINE 10

MOV AH, 02H

MOV DH, 10

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLJ

INT 21H

; ================ LINE 11

MOV AH, 02H

MOV DH, 11

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLK

INT 21H

; ================ LINE 12

MOV AH, 02H

MOV DH, 12

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLL

INT 21H

; ================ LINE 13

MOV AH, 02H

MOV DH, 13

MOV DL, 1

28
INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLM

INT 21H

; ================ LINE 14

MOV AH, 02H

MOV DH, 14

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLN

INT 21H

; ================ LINE 15

MOV AH, 02H

MOV DH, 15

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLO

INT 21H

; ================ LINE 16

MOV AH, 02H

MOV DH, 16

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLP

INT 21H

29
; ================ LINE 17

MOV AH, 02H

MOV DH, 17

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLQ

INT 21H

; ================ LINE 18

MOV AH, 02H

MOV DH, 18

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLR

INT 21H

; ================ LINE 19

MOV AH, 02H

MOV DH, 19

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLS

INT 21H

; ================ LINE 20

MOV AH, 02H

MOV DH, 20

MOV DL, 1

INT 10H

30
MOV AH, 09H

MOV DX, OFFSET SPLT

INT 21H

; ================ LINE 21

MOV AH, 02H

MOV DH, 21

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLU

INT 21H

; ================ LINE 22

MOV AH, 02H

MOV DH, 22

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET SPLV

INT 21H

; ================ PAUSE

MOV AH, 02H

MOV DH, 17

MOV DL, 22

INT 10H

MOV AH, 0AH

MOV DX, OFFSET TESTING

INT 21H

; ================ INTERFACE OUTPUT ================

31
; ================ CLEARS THE SCREEN

MOV AX, 03H

INT 10H

; ================ LINE 1

MOV AH, 02H

MOV DH, 1

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRA

INT 21H

; ================ LINE 2

MOV AH, 02H

MOV DH, 2

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRB

INT 21H

; ================ LINE 3

MOV AH, 02H

MOV DH, 3

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRC

INT 21H

; ================ LINE 4

MOV AH, 02H

32
MOV DH, 4

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRD

INT 21H

; ================ LINE 5

MOV AH, 02H

MOV DH, 5

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRE

INT 21H

; ================ LINE 6

MOV AH, 02H

MOV DH, 6

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRF

INT 21H

; ================ LINE 7

MOV AH, 02H

MOV DH, 7

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRG

33
INT 21H

; ================ LINE 8

MOV AH, 02H

MOV DH, 8

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRH

INT 21H

; ================ LINE 9

MOV AH, 02H

MOV DH, 9

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRI

INT 21H

; ================ LINE 10

MOV AH, 02H

MOV DH, 10

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRJ

INT 21H

; ================ LINE 11

MOV AH, 02H

MOV DH, 11

MOV DL, 1

34
INT 10H

MOV AH, 09H

MOV DX, OFFSET STRK

INT 21H

; ================ LINE 12

MOV AH, 02H

MOV DH, 12

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRL

INT 21H

; ================ LINE 13

MOV AH, 02H

MOV DH, 13

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRM

INT 21H

; ================ LINE 14

MOV AH, 02H

MOV DH, 14

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRN

INT 21H

35
; ================ LINE 15

MOV AH, 02H

MOV DH, 15

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRO

INT 21H

; ================ LINE 16

MOV AH, 02H

MOV DH, 16

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRP

INT 21H

; ================ LINE 17

MOV AH, 02H

MOV DH, 17

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRQ

INT 21H

; ================ LINE 18

MOV AH, 02H

MOV DH, 18

MOV DL, 1

INT 10H

36
MOV AH, 09H

MOV DX, OFFSET STRR

INT 21H

; ================ LINE 19

MOV AH, 02H

MOV DH, 19

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRS

INT 21H

; ================ LINE 20

MOV AH, 02H

MOV DH, 20

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRT

INT 21H

; ================ LINE 21

MOV AH, 02H

MOV DH, 21

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRU

INT 21H

; ================ LINE 22

MOV AH, 02H

37
MOV DH, 22

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRV

INT 21H

; ================ LINE 23

MOV AH, 02H

MOV DH, 23

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRW

INT 21H

; ================ LINE 24

MOV AH, 02H

MOV DH, 24

MOV DL, 1

INT 10H

MOV AH, 09H

MOV DX, OFFSET STRX

INT 21H

; ================ INPUTS ==========

; ================ NAME

MOV AH, 02H

MOV DH, 10

MOV DL, 21

INT 10H

MOV AH, 0AH

38
MOV DX, OFFSET HNAME

INT 21H

; ================ NICKNAME

MOV AH, 02H

MOV DH, 10

MOV DL, 56

INT 10H

MOV AH, 0AH

MOV DX, OFFSET NICKNAME

INT 21H

; ================ TELEPHONE NUMBER

MOV AH, 02H

MOV DH, 11

MOV DL, 57

INT 10H

MOV AH, 0AH

MOV DX, OFFSET LOCALAREA

INT 21H

MOV AH, 02H

MOV DH, 11

MOV DL, 60

INT 10H

MOV AH, 0AH

MOV DX, OFFSET COMPANY

INT 21H

MOV AH, 02H

MOV DH, 11

MOV DL, 64

INT 10H

39
MOV AH, 0AH

MOV DX, OFFSET NUMBER

INT 21H

; ================ ADDRESS

MOV AH, 02H

MOV DH, 12

MOV DL, 21

INT 10H

MOV AH, 0AH

MOV DX, OFFSET HADDRESS

INT 21H

; ================ BIRTHDAY

MOV AH, 02H

MOV DH, 13

MOV DL, 21

INT 10H

MOV AH, 0AH

MOV DX, OFFSET BIRTHDAY

INT 21H

; ================ AGE

MOV AH, 02H

MOV DH, 13

MOV DL, 56

INT 10H

MOV AH, 0AH

MOV DX, OFFSET AGE

INT 21H

40
; ================ COLOR 1

MOV AH, 02H

MOV DH, 16

MOV DL, 18

INT 10H

MOV AH, 0AH

MOV DX, OFFSET CONE

INT 21H

; ================ COLOR 2

MOV AH, 02H

MOV DH, 17

MOV DL, 18

INT 10H

MOV AH, 0AH

MOV DX, OFFSET CTWO

INT 21H

; ================ COLOR 3

MOV AH, 02H

MOV DH, 18

MOV DL, 18

INT 10H

MOV AH, 0AH

MOV DX, OFFSET CTHREE

INT 21H

; ================ ACTRESS 1

MOV AH, 02H

MOV DH, 20

MOV DL, 18

INT 10H

41
MOV AH, 0AH

MOV DX, OFFSET AONE

INT 21H

; ================ ACTESSS 2

MOV AH, 02H

MOV DH, 21

MOV DL, 18

INT 10H

MOV AH, 0AH

MOV DX, OFFSET ATWO

INT 21H

; ================ MOTTO

MOV AH, 02H

MOV DH, 22

MOV DL, 17

INT 10H

MOV AH, 0AH

MOV DX, OFFSET MOTTO

INT 21H

MOV AH, 02H

MOV DH, 24

MOV DL, 1

INT 10H

INT 20H

END MAIN

END

42
Notice the comments help greatly on the source code? Also, you notice how I make “pages” on my

program? The first page has a SPL (which means Splash) variable and the other page has STR (which

means String) variable.

A. ASCII Characters

Now, you notice the somewhat garbage characters like „Û‟? That‟s an ASCII character,

unfortunately my Word Processor can‟t show the real character of it, the real character of it is like

a gray block. But if you want to see the real character of it, go to the DOS mode and view it.

ASCII characters have a corresponding equivalent (1 – 256). For example the ASCII value of „A‟

is 65. So other more ASCII characters just hold ALT then press a number (on the numpad) then

release the ALT key, and then there you have it: an ASCII character.

B. Accepting Some Strings (SCANF)

Before we call the SCANF function, we should correctly make a variable for it, take this example

from the MP1:

NICKNAME DB 14,?,13 DUP (?)

43
Actually this requires some BLOODY explanation (actually, it took me days to figure this one

out) and I‟ll explain it later, but for now this is what that do: It defines a variable “NICKNAME”

with 14 space. Ok? Easy? Ok, this is our syntax (THIS IS JUST FOR NOW!):

<VARIABLE NAME> DB <SIZE>,?,<SIZE> DUP (?)

Where the <SIZE> is the size of your variable for input. Ok, now that we have a variable to put

our inputted text let‟s do the SCANF function. Take a look in this example:

MOV AH, 0AH

MOV DX, OFFSET NICKNAME

INT 21H

This function accepts input, then stores it to the variable “NICKNAME”. You might notice the

word “OFFSET”, offset means the memory location of “NICKNAME”. So, the syntax would be:

MOV AH, 0AH

MOV DX, OFFSET <VARIABLE NAME>

INT 21H

And that‟s it! All of the remaining codes there are tackled previously. Told you our next lesson

would be easier =) Ok, our next lesson would be hard but more exciting, so just hang-on, it will be

fun!

44
IV. MP2: TEXT, SOUNDS, AND GRAPHICS!

Are you ready now? This is I should say, the hardest MP of all but also this is the most enjoyable MP of

all. On our MP2, we are told to make a program that can do Colored Text, Blinking Text, Sounds, and

Graphics. Whoa! So many? So exciting! =) Just take a glance of my source code of it. And don‟t even try

to encode everything on it! Its almost 3000+ lines!

PMCMP2.ASM

; FILENAME : PMCMP2.ASM

; PROGRAMMED BY : MELJUN P. CORTES

; DATE STARTED : OCTOBER 6, 2005

; DATE FINISHED : ______________________

WRITE_BIGLETTERXY MACRO X, Y, CHARACTER, COLOR2

LOCAL MAIN, START, PART_2, EXIT_LABEL

LOCAL BIG_A, BIG_B, BIG_C, BIG_D, BIG_E, BIG_F, BIG_G, BIG_H, BIG_I, BIG_J, BIG_K, BIG_L, BIG_M,

BIG_N, BIG_O, BIG_P, BIG_Q, BIG_R, BIG_S, BIG_T, BIG_U, BIG_V, BIG_W, BIG_X, BIG_Y, BIG_Z

LOCAL BIG_A2, BIG_B2, BIG_C2, BIG_D2, BIG_E2, BIG_F2, BIG_G2, BIG_H2, BIG_I2, BIG_J2, BIG_K2,

BIG_L2, BIG_M2, BIG_N2, BIG_O2, BIG_P2, BIG_Q2, BIG_R2, BIG_S2, BIG_T2, BIG_U2, BIG_V2, BIG_W2, BIG_X2,

BIG_Y2, BIG_Z2

MAIN:

JMP START

START:

MOV CHARACTER2, CHARACTER

MOV COLOR, COLOR2

MOV COLUMN, X

MOV ROW, Y

MOV STRING_SIZE, 5

45
CMP CHARACTER2, 'A'

JE BIG_A

CMP CHARACTER2, 'B'

JE BIG_B

CMP CHARACTER2, 'C'

JE BIG_C

CMP CHARACTER2, 'D'

JE BIG_D

CMP CHARACTER2, 'E'

JE BIG_E

CMP CHARACTER2, 'F'

JE BIG_F

CMP CHARACTER2, 'G'

JE BIG_G

CMP CHARACTER2, 'H'

JE BIG_H

CMP CHARACTER2, 'I'

JE BIG_I

CMP CHARACTER2, 'J'

JE BIG_J

CMP CHARACTER2, 'K'

JE BIG_K

JMP PART_2

BIG_A:

CALL BIG_A2

JMP EXIT_LABEL

BIG_B:

CALL BIG_B2

JMP EXIT_LABEL

BIG_C:

CALL BIG_C2

JMP EXIT_LABEL

BIG_D:

CALL BIG_D2

46
JMP EXIT_LABEL

BIG_E:

CALL BIG_E2

JMP EXIT_LABEL

BIG_F:

CALL BIG_F2

JMP EXIT_LABEL

BIG_G:

CALL BIG_G2

JMP EXIT_LABEL

BIG_H:

CALL BIG_H2

JMP EXIT_LABEL

BIG_I:

CALL BIG_I2

JMP EXIT_LABEL

BIG_J:

CALL BIG_J2

JMP EXIT_LABEL

BIG_K:

CALL BIG_K2

JMP EXIT_LABEL

PART_2:

CMP CHARACTER2, 'L'

JE BIG_L

CMP CHARACTER2, 'M'

JE BIG_M

CMP CHARACTER2, 'N'

JE BIG_N

CMP CHARACTER2, 'O'

JE BIG_O

CMP CHARACTER2, 'P'

JE BIG_P

CMP CHARACTER2, 'Q'

JE BIG_Q

47
CMP CHARACTER2, 'R'

JE BIG_R

CMP CHARACTER2, 'S'

JE BIG_S

CMP CHARACTER2, 'T'

JE BIG_T

CMP CHARACTER2, 'U'

JE BIG_U

CMP CHARACTER2, 'V'

JE BIG_V

CMP CHARACTER2, 'W'

JE BIG_W

CMP CHARACTER2, 'X'

JE BIG_X

CMP CHARACTER2, 'Y'

JE BIG_Y

CMP CHARACTER2, 'Z'

JE BIG_Z

JMP EXIT_LABEL

BIG_L:

CALL BIG_L2

JMP EXIT_LABEL

BIG_M:

CALL BIG_M2

JMP EXIT_LABEL

BIG_N:

CALL BIG_N2

JMP EXIT_LABEL

BIG_O:

CALL BIG_O2

JMP EXIT_LABEL

BIG_P:

CALL BIG_P2

JMP EXIT_LABEL

BIG_Q:

48
CALL BIG_Q2

JMP EXIT_LABEL

BIG_R:

CALL BIG_R2

JMP EXIT_LABEL

BIG_S:

CALL BIG_S2

JMP EXIT_LABEL

BIG_T:

CALL BIG_T2

JMP EXIT_LABEL

BIG_U:

CALL BIG_U2

JMP EXIT_LABEL

BIG_V:

CALL BIG_V2

JMP EXIT_LABEL

BIG_W:

CALL BIG_W2

JMP EXIT_LABEL

BIG_X:

CALL BIG_X2

JMP EXIT_LABEL

BIG_Y:

CALL BIG_Y2

JMP EXIT_LABEL

BIG_Z:

CALL BIG_Z2

JMP EXIT_LABEL

BIG_A2:

WRITE_LINE " ÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

49
JMP EXIT_LABEL

BIG_B2:

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛ "

JMP EXIT_LABEL

BIG_C2:

WRITE_LINE " ÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE "Û "

WRITE_LINE "Û "

WRITE_LINE " ÛÛÛÛ"

JMP EXIT_LABEL

BIG_D2:

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛ "

JMP EXIT_LABEL

BIG_E2:

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE "ÛÛÛÛÛ"

JMP EXIT_LABEL

BIG_F2:

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE "Û "

JMP EXIT_LABEL

50
BIG_G2:

WRITE_LINE " ÛÛÛ "

WRITE_LINE "Û "

WRITE_LINE "Û ÛÛÛ"

WRITE_LINE "Û Û"

WRITE_LINE " ÛÛÛ "

JMP EXIT_LABEL

BIG_H2:

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

JMP EXIT_LABEL

BIG_I2:

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE "ÛÛÛÛÛ"

JMP EXIT_LABEL

BIG_J2:

WRITE_LINE " Û"

WRITE_LINE " Û"

WRITE_LINE " Û"

WRITE_LINE "Û Û"

WRITE_LINE " ÛÛÛ "

JMP EXIT_LABEL

BIG_K2:

WRITE_LINE "Û Û"

WRITE_LINE "Û Û "

WRITE_LINE "ÛÛÛ "

WRITE_LINE "Û Û "

WRITE_LINE "Û Û"

JMP EXIT_LABEL

BIG_L2:

51
WRITE_LINE "Û "

WRITE_LINE "Û "

WRITE_LINE "Û "

WRITE_LINE "Û "

WRITE_LINE "ÛÛÛÛÛ"

JMP EXIT_LABEL

BIG_M2:

WRITE_LINE " Û Û "

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

JMP EXIT_LABEL

BIG_N2:

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛ Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û ÛÛ"

WRITE_LINE "Û Û"

JMP EXIT_LABEL

BIG_O2:

WRITE_LINE " ÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE " ÛÛÛ "

JMP EXIT_LABEL

BIG_P2:

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û "

WRITE_LINE "Û "

JMP EXIT_LABEL

BIG_Q2:

WRITE_LINE " ÛÛÛ "

52
WRITE_LINE "Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û ÛÛ"

WRITE_LINE " ÛÛÛÛ"

JMP EXIT_LABEL

BIG_R2:

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û"

WRITE_LINE "ÛÛÛÛ "

WRITE_LINE "Û Û "

WRITE_LINE "Û Û"

JMP EXIT_LABEL

BIG_S2:

WRITE_LINE " ÛÛÛÛ"

WRITE_LINE "Û "

WRITE_LINE " ÛÛÛ "

WRITE_LINE " Û"

WRITE_LINE "ÛÛÛÛ "

JMP EXIT_LABEL

BIG_T2:

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

JMP EXIT_LABEL

BIG_U2:

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE "Û Û"

WRITE_LINE " ÛÛÛ "

JMP EXIT_LABEL

BIG_V2:

WRITE_LINE "Û Û"

WRITE_LINE " Û Û "

53
WRITE_LINE " Û Û "

WRITE_LINE " Û Û "

WRITE_LINE " Û "

JMP EXIT_LABEL

BIG_W2:

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE "Û Û Û"

WRITE_LINE " Û Û "

JMP EXIT_LABEL

BIG_X2:

WRITE_LINE "Û Û"

WRITE_LINE " Û Û "

WRITE_LINE " Û "

WRITE_LINE " Û Û "

WRITE_LINE "Û Û"

JMP EXIT_LABEL

BIG_Y2:

WRITE_LINE "Û Û"

WRITE_LINE " Û Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

JMP EXIT_LABEL

BIG_Z2:

WRITE_LINE "ÛÛÛÛÛ"

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE " Û "

WRITE_LINE "ÛÛÛÛÛ"

JMP EXIT_LABEL

EXIT_LABEL:

ENDM

54
WRITE_BIGBIGLETTERXY MACRO X, Y, CHARACTER, COLOR2

LOCAL MAIN, START, PART_2, EXIT_LABEL

LOCAL BIG_A, BIG_B, BIG_C, BIG_D, BIG_E, BIG_F, BIG_G, BIG_H, BIG_I, BIG_J, BIG_K, BIG_L, BIG_M,

BIG_N, BIG_O, BIG_P, BIG_Q, BIG_R, BIG_S, BIG_T, BIG_U, BIG_V, BIG_W, BIG_X, BIG_Y, BIG_Z

LOCAL BIG_A2, BIG_B2, BIG_C2, BIG_D2, BIG_E2, BIG_F2, BIG_G2, BIG_H2, BIG_I2, BIG_J2, BIG_K2,

BIG_L2, BIG_M2, BIG_N2, BIG_O2, BIG_P2, BIG_Q2, BIG_R2, BIG_S2, BIG_T2, BIG_U2, BIG_V2, BIG_W2, BIG_X2,

BIG_Y2, BIG_Z2

MAIN:

JMP START

START:

MOV CHARACTER2, CHARACTER

MOV COLOR, COLOR2

MOV COLUMN, X

MOV ROW, Y

MOV STRING_SIZE, 11

CMP CHARACTER2, 'A'

JE BIG_A

CMP CHARACTER2, 'B'

JE BIG_B

CMP CHARACTER2, 'C'

JE BIG_C

CMP CHARACTER2, 'D'

JE BIG_D

CMP CHARACTER2, 'E'

JE BIG_E

CMP CHARACTER2, 'F'

JE BIG_F

CMP CHARACTER2, 'G'

JE BIG_G

CMP CHARACTER2, 'H'

JE BIG_H

CMP CHARACTER2, 'I'

JE BIG_I

55
CMP CHARACTER2, 'J'

JE BIG_J

CMP CHARACTER2, 'K'

JE BIG_K

JMP PART_2

BIG_A:

CALL BIG_A2

JMP EXIT_LABEL

BIG_B:

CALL BIG_B2

JMP EXIT_LABEL

BIG_C:

CALL BIG_C2

JMP EXIT_LABEL

BIG_D:

CALL BIG_D2

JMP EXIT_LABEL

BIG_E:

CALL BIG_E2

JMP EXIT_LABEL

BIG_F:

CALL BIG_F2

JMP EXIT_LABEL

BIG_G:

CALL BIG_G2

JMP EXIT_LABEL

BIG_H:

CALL BIG_H2

JMP EXIT_LABEL

BIG_I:

CALL BIG_I2

JMP EXIT_LABEL

BIG_J:

CALL BIG_J2

JMP EXIT_LABEL

56
BIG_K:

CALL BIG_K2

JMP EXIT_LABEL

PART_2:

CMP CHARACTER2, 'L'

JE BIG_L

CMP CHARACTER2, 'M'

JE BIG_M

CMP CHARACTER2, 'N'

JE BIG_N

CMP CHARACTER2, 'O'

JE BIG_O

CMP CHARACTER2, 'P'

JE BIG_P

CMP CHARACTER2, 'Q'

JE BIG_Q

CMP CHARACTER2, 'R'

JE BIG_R

CMP CHARACTER2, 'S'

JE BIG_S

CMP CHARACTER2, 'T'

JE BIG_T

CMP CHARACTER2, 'U'

JE BIG_U

CMP CHARACTER2, 'V'

JE BIG_V

CMP CHARACTER2, 'W'

JE BIG_W

CMP CHARACTER2, 'X'

JE BIG_X

CMP CHARACTER2, 'Y'

JE BIG_Y

CMP CHARACTER2, 'Z'

JE BIG_Z

JMP EXIT_LABEL

57
BIG_L:

CALL BIG_L2

JMP EXIT_LABEL

BIG_M:

CALL BIG_M2

JMP EXIT_LABEL

BIG_N:

CALL BIG_N2

JMP EXIT_LABEL

BIG_O:

CALL BIG_O2

JMP EXIT_LABEL

BIG_P:

CALL BIG_P2

JMP EXIT_LABEL

BIG_Q:

CALL BIG_Q2

JMP EXIT_LABEL

BIG_R:

CALL BIG_R2

JMP EXIT_LABEL

BIG_S:

CALL BIG_S2

JMP EXIT_LABEL

BIG_T:

CALL BIG_T2

JMP EXIT_LABEL

BIG_U:

CALL BIG_U2

JMP EXIT_LABEL

BIG_V:

CALL BIG_V2

JMP EXIT_LABEL

BIG_W:

CALL BIG_W2

58
JMP EXIT_LABEL

BIG_X:

CALL BIG_X2

JMP EXIT_LABEL

BIG_Y:

CALL BIG_Y2

JMP EXIT_LABEL

BIG_Z:

CALL BIG_Z2

JMP EXIT_LABEL

BIG_A2:

WRITE_LINE " °°°°°°°°° "

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_B2:

WRITE_LINE "°°°°°°°°°° "

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°°°°°°°°°° "

59
JMP EXIT_LABEL

BIG_C2:

WRITE_LINE " °°°°°°°°°°"

WRITE_LINE "°°±±±±±±±±°"

WRITE_LINE "°±± ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± Û ±±±±±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°±± ±°"

WRITE_LINE "°°±±±±±±±±°"

WRITE_LINE " °°°°°°°°°°"

JMP EXIT_LABEL

BIG_D2:

WRITE_LINE "°°°°°°°°°° "

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°°°°°°°°°° "

JMP EXIT_LABEL

BIG_E2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

60
WRITE_LINE "°± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_F2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± Û ±±±±±°"

WRITE_LINE "°± ±°°°°°"

WRITE_LINE "°±±±±±° "

WRITE_LINE "°°°°°°° "

JMP EXIT_LABEL

BIG_G2:

WRITE_LINE " °°°°°°°°°°"

WRITE_LINE "°°±±±±±±±±°"

WRITE_LINE "°±± ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± Û ÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE " °°°°°°°°° "

JMP EXIT_LABEL

BIG_H2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± Û Û ±°"

61
WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_I2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°±±± Û ±±±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_J2:

WRITE_LINE " °°°°°°°"

WRITE_LINE " °±±±±±°"

WRITE_LINE " °± ±°"

WRITE_LINE "°°°°°± Û ±°"

WRITE_LINE "°±±±±± Û ±°"

WRITE_LINE "°± ± Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE " °°°°°°°°° "

JMP EXIT_LABEL

BIG_K2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

62
WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛ ±±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_L2:

WRITE_LINE "°°°°°°° "

WRITE_LINE "°±±±±±° "

WRITE_LINE "°± ±° "

WRITE_LINE "°± Û ±° "

WRITE_LINE "°± Û ±°°°°°"

WRITE_LINE "°± Û ±±±±±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_M2:

WRITE_LINE " °°°°°°°°° "

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

63
BIG_N2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛ Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û ÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_O2:

WRITE_LINE " °°°°°°°°° "

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE " °°°°°°°°° "

JMP EXIT_LABEL

BIG_P2:

WRITE_LINE "°°°°°°°°°° "

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û ±±°"

WRITE_LINE "°± Û ±±±±°°"

WRITE_LINE "°± ±°°°° "

64
WRITE_LINE "°±±±±±° "

WRITE_LINE "°°°°°°° "

JMP EXIT_LABEL

BIG_Q2:

WRITE_LINE " °°°°°°°°° "

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û ÛÛ ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°±± ±°"

WRITE_LINE "°°±±±±±±±±°"

WRITE_LINE " °°°°°°°°°°"

JMP EXIT_LABEL

BIG_R2:

WRITE_LINE "°°°°°°°°°° "

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_S2:

WRITE_LINE " °°°°°°°°°°"

WRITE_LINE "°°±±±±±±±±°"

WRITE_LINE "°±± ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛ ±°"

65
WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛ ±°"

WRITE_LINE "°± ±±°"

WRITE_LINE "°±±±±±±±±°°"

WRITE_LINE "°°°°°°°°°° "

JMP EXIT_LABEL

BIG_T2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°±±± Û ±±±°"

WRITE_LINE "°°°± Û ±°°°"

WRITE_LINE " °± Û ±° "

WRITE_LINE " °± ±° "

WRITE_LINE " °±±±±±° "

WRITE_LINE " °°°°°°° "

JMP EXIT_LABEL

BIG_U2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± Û ± Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ÛÛÛ ±°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE " °°°°°°°°° "

JMP EXIT_LABEL

BIG_V2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

66
WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°±± Û Û ±±°"

WRITE_LINE "°°± Û Û ±°°"

WRITE_LINE " °± Û ±° "

WRITE_LINE " °±± ±±° "

WRITE_LINE " °°±±±±±°° "

WRITE_LINE " °°°°°°° "

JMP EXIT_LABEL

BIG_W2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°±± ±±°"

WRITE_LINE "°°±±±±±±±°°"

WRITE_LINE " °°°°°°°°° "

JMP EXIT_LABEL

BIG_X2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°±± Û ±±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

BIG_Y2:

67
WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ± ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°± Û Û ±°"

WRITE_LINE "°±± Û ±±°"

WRITE_LINE "°°±± Û ±±°°"

WRITE_LINE " °°± Û ±°° "

WRITE_LINE " °± ±° "

WRITE_LINE " °±±±±±° "

WRITE_LINE " °°°°°°° "

JMP EXIT_LABEL

BIG_Z2:

WRITE_LINE "°°°°°°°°°°°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°±± Û ±±°"

WRITE_LINE "°± Û ±°"

WRITE_LINE "°± ÛÛÛÛÛ ±°"

WRITE_LINE "°± ±°"

WRITE_LINE "°±±±±±±±±±°"

WRITE_LINE "°°°°°°°°°°°"

JMP EXIT_LABEL

EXIT_LABEL:

ENDM

WRITE_LINE MACRO STRING

GOTOXY COLUMN, ROW

WRITE_STRING STRING, STRING_SIZE, COLOR

NEWLINE

ENDM

NEWLINE MACRO

68
ADD ROW, 1

GOTOXY COLUMN, ROW

ENDM

WRITE_STRING MACRO STRING, STRING_SIZE, COLOR

LOCAL MAIN, START, VAR, LOOP_LABEL

MAIN: JMP START

VAR DB STRING,'$'

START:

MOV AH, 09h

MOV BH, 0

MOV BL, COLOR

MOV SI, OFFSET VAR

ADD SI, STRING_SIZE

MOV CX, STRING_SIZE

DEC SI

LOOP_LABEL:

MOV AL, [SI]

INT 10h

DEC SI

LOOP LOOP_LABEL

ENDM

; ==================== GOTOXY

GOTOXY MACRO X,Y

SAVE_REGISTER

MOV AH, 02h

MOV BH, 0

MOV DH, Y

MOV DL, X

INT 10h

69
RESTORE_REGISTER

ENDM

; ==================== PRINT_LINE

PRINT_LINE MACRO LINE, STRING

LOCAL MAIN, START, VAR

MAIN: JMP START

VAR DW STRING

START:

SAVE_REGISTER

GOTOXY 1, LINE

MOV AH, 09h

MOV DX, VAR

INT 21h

RESTORE_REGISTER

ENDM

; ==================== PRINTF

PRINTF MACRO STRING

LOCAL MAIN, START, VAR

MAIN: JMP START

VAR DB STRING,'$'

START:

SAVE_REGISTER

MOV AH, 09h

MOV DX, OFFSET VAR

INT 21h

RESTORE_REGISTER

ENDM

70
; ==================== CLRSCR

CLRSCR MACRO

MOV AX, 03h

INT 10h

ENDM

; ==================== SET_VIDEO_MODE

SET_VIDEO_MODE MACRO MODE

SAVE_REGISTER

MOV AH,00h

MOV AL,MODE

INT 10h

RESTORE_REGISTER

ENDM

; ==================== TERMINATE_PROGRAM

TERMINATE_PROGRAM MACRO

INT 20h

ENDM

; ==================== GET_KEYSTROKE

GET_KEYSTROKE MACRO

MOV AX,0000h

INT 16h

ENDM

; ==================== PLOT_PIXEL

PLOT_PIXEL MACRO X, Y, COLOR

SAVE_REGISTER

MOV BX,X ;put X location into DI

MOV DX,Y ;and Y into DX

MOV AX, 320

71
MUL DX

ADD BX, AX

MOV DI, BX

MOV AL, COLOR

STOSB

RESTORE_REGISTER

ENDM

; ==================== SAVE_REGISTER

SAVE_REGISTER MACRO

PUSH AX

PUSH BX

PUSH CX

PUSH DX

ENDM

; ==================== RESTORE_REGISTER

RESTORE_REGISTER MACRO

POP AX

POP BX

POP CX

POP DX

ENDM

; ==================== WRITE_CHARACTER

WRITE_CHARACTER MACRO CHARACTER, COLOR

SAVE_REGISTER

MOV AH, 09h

MOV BH, 0

MOV BL, COLOR

MOV CX, 1

MOV AL, CHARACTER

72
INT 10h

RESTORE_REGISTER

ENDM

; ==================== WRITE_CHARACTERXY

WRITE_CHARACTERXY MACRO X, Y, CHARACTER, COLOR

SAVE_REGISTER

GOTOXY X, Y

WRITE_CHARACTER CHARACTER, COLOR

RESTORE_REGISTER

ENDM

; ==================== WRITE_STRINGXY

WRITE_STRINGXY MACRO X, Y, STRING, SIZE, COLOR

LOCAL MAIN, START, VAR, LOOP_LABEL

MAIN: JMP START

VAR DB STRING,'$'

START:

SAVE_REGISTER

GOTOXY X, Y

MOV AH, 09h

MOV BH, 0

MOV BL, COLOR

MOV SI, OFFSET VAR

ADD SI, SIZE

MOV CX, SIZE

DEC SI

LOOP_LABEL:

MOV AL, [SI]

INT 10h

DEC SI

LOOP LOOP_LABEL

RESTORE_REGISTER

ENDM

73
; ==================== PROGRAM STARTS ====================

.MODEL TINY

.CODE

ORG 100h

MAIN: JMP START

stor dw 0 ;our memory location storage

startaddr dw 0a000h ;start of video memory

colour db 1

COLOR DB ?

COLUMN DB ?

STRING_SIZE DW ?

ROW DB ?

CHARACTER2 DB ?

RED EQU 00000100B

GREEN EQU 00000010B

BLUE EQU 00000001B

WHITE EQU 00001111B

BLINKING EQU 10001111B

RED_B EQU 01001111B

GREEN_B EQU 00101111B

BLUE_B EQU 00011111B

RED_BB EQU 00011100B

GREEN_BB EQU 00011010B

BLUE_BB EQU 00011001B

WHITE_BB EQU 00011111B

GB_BB EQU 00011011B

RB_BB EQU 00011101B

74
RG_BB EQU 00011110B

BLINKING_BB EQU 10011111B

BLUE_WB EQU 01111001B

REVERSE EQU 01110000B

START:

CLRSCR

WRITE_STRINGXY 1, 1, "°°°°°°°°°° °°°°°°°°°° °°°°°°°°° °°°°°°°°°° °°°°°°° °°°°°°°°°°° °°°°°°°°° ", 77,

WHITE

WRITE_STRINGXY 1, 2, "°±±±±±±±±°°°±±±±±±±±°°°°±±±±±±±°°°±±±±±±±±°°°±±±±±° °±±±±±±±±±°°°±±±±±±±°°", 77,

WHITE

WRITE_STRINGXY 1, 3, "°± ±±°°± ±±°°±± ±±°°± ±±°°± ±° °± ±°°±± ±±°", 77,

WHITE

WRITE_STRINGXY 1, 4, "°± ÛÛÛÛ ±°°± ÛÛÛÛ ±°°± ÛÛÛ ±°°± ÛÛÛÛ ±°°± Û ±° °± ÛÛÛÛÛ ±°°± Û Û ±°", 77,

WHITE

WRITE_STRINGXY 1, 5, "°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û ±°°°°°°± Û ±°°± Û Û Û ±°", 77,

WHITE

WRITE_STRINGXY 1, 6, "°± ÛÛÛÛ ±°°± ÛÛÛÛ ±°°± Û Û ±°°± ÛÛÛÛ ±°°± Û ±±±±±°°± ÛÛÛÛÛ ±°°± Û Û Û ±°", 77,

WHITE

WRITE_STRINGXY 1, 7, "°± Û ±±°°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û ±°°± Û ±°°± Û Û Û ±°", 77,

WHITE

WRITE_STRINGXY 1, 8, "°± Û ±±±±°°°± Û Û ±°°± ÛÛÛ ±°°± ÛÛÛÛ ±°°± ÛÛÛÛÛ ±°°± ÛÛÛÛÛ ±°°± Û Û Û ±°", 77,

WHITE

WRITE_STRINGXY 1, 9, "°± ±°°°° °± ± ±°°±± ±±°°± ±±°°± ±°°± ±°°± ±°", 77,

WHITE

WRITE_STRINGXY 1, 10, "°±±±±±° °±±±±±±±±±°°°±±±±±±±°°°±±±±±±±±°°°±±±±±±±±±°°±±±±±±±±±°°±±±±±±±±±°", 77,

WHITE

WRITE_STRINGXY 1, 11, "°°°°°°° °°°°°°°°°°° °°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°", 77,

WHITE

75
WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 14, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 15, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 16, " ÛÛÛ ÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 17, " ÛÛÛ ÛÛÛ By: Castillo, Paul Mark ", 77,

WHITE

WRITE_STRINGXY 1, 18, " ÛÛÛ ÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 19, " ÛÛÛ ÛÛÛ Special Thanks to: ", 77,

WHITE

WRITE_STRINGXY 1, 20, " ÛÛÛ ÛÛÛ Evenbit ", 77,

WHITE

WRITE_STRINGXY 1, 21, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ Ralp ", 77,

WHITE

WRITE_STRINGXY 1, 22, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ And Many Many More... ", 77,

WHITE

WRITE_STRINGXY 1, 23, " ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press ANY KEY To Ret To Main Menu ", 77,

WHITE

GOTOXY 58, 24

GET_KEYSTROKE

; ==================== MAIN MENU

MAIN_MENU:

CLRSCR

76
WRITE_STRINGXY 1, 1, " °°°°°°°°° °°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° ", 77,

BLUE_B

WRITE_STRINGXY 1, 2, " °°±±±±±±±°° °°±±±±±±±°° °±±±±±±±±±° °±±±±±±±±±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 3, " °±± ±±° °±± ±±° °± ±° °± ± ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 4, " °± Û Û ±° °± ÛÛÛ ±° °± ÛÛÛÛÛ ±° °± Û Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 5, " °± Û Û Û ±° °± Û Û ±° °± Û ±° °± ÛÛ Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 6, " °± Û Û Û ±° °± ÛÛÛÛÛ ±° °±±± Û ±±±° °± Û Û Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 7, " °± Û Û Û ±° °± Û Û ±° °± Û ±° °± Û ÛÛ ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 8, " °± Û Û Û ±° °± Û ± Û ±° °± ÛÛÛÛÛ ±° °± Û Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 9, " °± ±° °± ± ±° °± ±° °± ± ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 10, " °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 11, " °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° ", 77,

BLUE_B

WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " ", 77,

WHITE

WRITE_STRINGXY 1, 14, " 1. Colored Text ", 77,

WHITE

WRITE_STRINGXY 1, 15, " ", 77,

WHITE

WRITE_STRINGXY 1, 16, " 2. Blinking Text ", 77,

WHITE

WRITE_STRINGXY 1, 17, " ", 77,

WHITE

WRITE_STRINGXY 1, 18, " 3. Sounds ", 77,

WHITE

77
WRITE_STRINGXY 1, 19, " ", 77,

WHITE

WRITE_STRINGXY 1, 20, " 4. Graphics ", 77,

WHITE

WRITE_STRINGXY 1, 21, " ", 77,

WHITE

WRITE_STRINGXY 1, 22, " 5. Exit ", 77,

WHITE

WRITE_STRINGXY 1, 23, " ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press A NUMBER ", 77,

REVERSE

GOTOXY 58, 24

GET_KEY:

GET_KEYSTROKE

CMP AH,02h

JE OPTION1

CMP AH,03h

JE OPTION2

CMP AH,04h

JE OPTION3

CMP AH,05h

JE OPTION4

CMP AH,06h ;ESC key pressed?

JE OPTION5

JMP GET_KEY ;go get another keypress

OPTION1:

CALL COLORED_TEXT

JMP MAIN_MENU

78
OPTION2:

CALL BLINKING_TEXT

JMP MAIN_MENU

OPTION3:

CALL SOUNDS

JMP MAIN_MENU

OPTION4:

CALL GRAPHICS

JMP MAIN_MENU

OPTION5:

CALL EXIT

; ==================== COLORED TEXT

COLORED_TEXT:

CLRSCR

WRITE_STRINGXY 1, 1, " °°°°°°°°°° °°°°°°°°° °°°°°°° °°°°°°°°° °°°°°°°°°° °°°°°°°°°° ", 77,

RED_BB

WRITE_STRINGXY 1, 2, " °°±±±±±±±±° °°±±±±±±±°° °±±±±±° °°±±±±±±±°° °±±±±±±±±°° °°±±±±±±±±° ", 77,

GREEN_BB

WRITE_STRINGXY 1, 3, " °±± ±° °±± ±±° °± ±° °±± ±±° °± ±±° °±± ±° ", 77,

BLUE_BB

WRITE_STRINGXY 1, 4, " °± ÛÛÛÛ ±° °± ÛÛÛ ±° °± Û ±° °± ÛÛÛ ±° °± ÛÛÛÛ ±° °± ÛÛÛÛ ±° ", 77,

WHITE_BB

WRITE_STRINGXY 1, 5, " °± Û ±° °± Û Û ±° °± Û ±°°°°° °± Û Û ±° °± Û Û ±° °± Û ±° ", 77,

WHITE_BB

WRITE_STRINGXY 1, 6, " °± Û ±±±±±° °± Û Û ±° °± Û ±±±±±° °± Û Û ±° °± ÛÛÛÛ ±° °± ÛÛÛ ±° ", 77,

WHITE_BB

WRITE_STRINGXY 1, 7, " °± Û ±° °± Û Û ±° °± Û ±° °± Û Û ±° °± Û Û ±° °± Û ±° ", 77,

WHITE_BB

79
WRITE_STRINGXY 1, 8, " °± ÛÛÛÛ ±° °± ÛÛÛ ±° °± ÛÛÛÛÛ ±° °± ÛÛÛ ±° °± Û Û ±° °± ÛÛÛÛ ±° ", 77,

WHITE_BB

WRITE_STRINGXY 1, 9, " °±± ±° °±± ±±° °± ±° °±± ±±° °± ± ±° °± ±±° ", 77,

BLUE_BB

WRITE_STRINGXY 1, 10, " °°±±±±±±±±° °°±±±±±±±°° °±±±±±±±±±° °°±±±±±±±°° °±±±±±±±±±° °±±±±±±±±°° ", 77,

GREEN_BB

WRITE_STRINGXY 1, 11, " °°°°°°°°°° °°°°°°°°° °°°°°°°°°°° °°°°°°°°° °°°°°°°°°°° °°°°°°°°°° ", 77,

RED_BB

WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " ", 77,

WHITE

WRITE_STRINGXY 1, 14, " ", 77,

WHITE

WRITE_STRINGXY 1, 15, " ", 77,

WHITE

WRITE_STRINGXY 1, 16, " ", 77,

WHITE

WRITE_STRINGXY 1, 17, " ", 77,

WHITE

WRITE_STRINGXY 1, 18, " ", 77,

WHITE

WRITE_STRINGXY 1, 19, " ", 77,

WHITE

WRITE_STRINGXY 1, 20, " ", 77,

WHITE

WRITE_STRINGXY 1, 21, " ", 77,

WHITE

WRITE_STRINGXY 1, 22, " ", 77,

WHITE

WRITE_STRINGXY 1, 23, " ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press ANY KEY To Ret To Main Menu ", 77,

REVERSE

GOTOXY 58, 24

80
; ========== FOR 'R'

;WRITE_CHARACTERXY 10, 13, 'Û', RED

;WRITE_CHARACTERXY 11, 13, 'Û', RED

;WRITE_CHARACTERXY 12, 13, 'Û', RED

;WRITE_CHARACTERXY 13, 13, 'Û', RED

;WRITE_CHARACTERXY 10, 14, 'Û', RED

;WRITE_CHARACTERXY 14, 14, 'Û', RED

;WRITE_CHARACTERXY 10, 15, 'Û', RED

;WRITE_CHARACTERXY 11, 15, 'Û', RED

;WRITE_CHARACTERXY 12, 15, 'Û', RED

;WRITE_CHARACTERXY 13, 15, 'Û', RED

;WRITE_CHARACTERXY 10, 16, 'Û', RED

;WRITE_CHARACTERXY 13, 16, 'Û', RED

;WRITE_CHARACTERXY 10, 17, 'Û', RED

;WRITE_CHARACTERXY 14, 17, 'Û', RED

;

; ========== FOR 'G'

;WRITE_CHARACTERXY 17, 13, 'Û', GREEN

;WRITE_CHARACTERXY 18, 13, 'Û', GREEN

;WRITE_CHARACTERXY 19, 13, 'Û', GREEN

;WRITE_CHARACTERXY 20, 13, 'Û', GREEN

;WRITE_CHARACTERXY 16, 14, 'Û', GREEN

;WRITE_CHARACTERXY 16, 15, 'Û', GREEN

;WRITE_CHARACTERXY 18, 15, 'Û', GREEN

;WRITE_CHARACTERXY 19, 15, 'Û', GREEN

;WRITE_CHARACTERXY 20, 15, 'Û', GREEN

;WRITE_CHARACTERXY 16, 16, 'Û', GREEN

;WRITE_CHARACTERXY 20, 16, 'Û', GREEN

;WRITE_CHARACTERXY 17, 17, 'Û', GREEN

;WRITE_CHARACTERXY 18, 17, 'Û', GREEN

;WRITE_CHARACTERXY 19, 17, 'Û', GREEN

;

; ========== FOR 'B'

;WRITE_CHARACTERXY 22, 13, 'Û', BLUE

;WRITE_CHARACTERXY 23, 13, 'Û', BLUE

81
;WRITE_CHARACTERXY 24, 13, 'Û', BLUE

;WRITE_CHARACTERXY 25, 13, 'Û', BLUE

;WRITE_CHARACTERXY 22, 14, 'Û', BLUE

;WRITE_CHARACTERXY 26, 14, 'Û', BLUE

;WRITE_CHARACTERXY 22, 15, 'Û', BLUE

;WRITE_CHARACTERXY 23, 15, 'Û', BLUE

;WRITE_CHARACTERXY 24, 15, 'Û', BLUE

;WRITE_CHARACTERXY 25, 15, 'Û', BLUE

;WRITE_CHARACTERXY 22, 16, 'Û', BLUE

;WRITE_CHARACTERXY 26, 16, 'Û', BLUE

;WRITE_CHARACTERXY 22, 17, 'Û', BLUE

;WRITE_CHARACTERXY 23, 17, 'Û', BLUE

;WRITE_CHARACTERXY 24, 17, 'Û', BLUE

;WRITE_CHARACTERXY 25, 17, 'Û', BLUE

GET_KEYSTROKE

RET

; ==================== BLINKING TEXT

BLINKING_TEXT:

CLRSCR

WRITE_STRINGXY 1, 1, " °°°°°°°°°° °°°°°°° °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 2, " °±±±±±±±±°° °±±±±±° °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 3, " °± ±±° °± ±° °± ±° °± ± ±° °± ± ±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 4, " °± ÛÛÛÛ ±° °± Û ±° °± ÛÛÛÛÛ ±° °± Û Û ±° °± Û Û ±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 5, " °± Û Û ±° °± Û ±°°°°° °± Û ±° °± ÛÛ Û ±° °± Û Û ±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 6, " °± ÛÛÛÛ ±° °± Û ±±±±±° °±±± Û ±±±° °± Û Û Û ±° °± ÛÛÛ ±±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 7, " °± Û Û ±° °± Û ±° °± Û ±° °± Û ÛÛ ±° °± Û Û ±° ", 77,

BLINKING_BB

82
WRITE_STRINGXY 1, 8, " °± ÛÛÛÛ ±° °± ÛÛÛÛÛ ±° °± ÛÛÛÛÛ ±° °± Û Û ±° °± Û Û ±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 9, " °± ±±° °± ±° °± ±° °± ± ±° °± ± ±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 10, " °±±±±±±±±°° °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±±° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 11, " °°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° ", 77,

BLINKING_BB

WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " ", 77,

WHITE

WRITE_STRINGXY 1, 14, " ", 77,

WHITE

WRITE_STRINGXY 1, 15, " ", 77,

WHITE

WRITE_STRINGXY 1, 16, " ", 77,

WHITE

WRITE_STRINGXY 1, 17, " ", 77,

WHITE

WRITE_STRINGXY 1, 18, " ", 77,

WHITE

WRITE_STRINGXY 1, 19, " ", 77,

WHITE

WRITE_STRINGXY 1, 20, " ", 77,

WHITE

WRITE_STRINGXY 1, 21, " ", 77,

WHITE

WRITE_STRINGXY 1, 22, " ", 77,

WHITE

WRITE_STRINGXY 1, 23, " ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press ANY KEY To Ret To Main Menu ", 77,

REVERSE

GOTOXY 58, 24

83
GET_KEYSTROKE

RET

; ==================== SOUNDS

SOUNDS:

CLRSCR

WRITE_STRINGXY 1, 1, " °°°°°°°°°° °°°°°°°°° °°°°°°°°°°° °°°°°°°°°°° °°°°°°°°°° °°°°°°°°°° ", 77,

BLUE_B

WRITE_STRINGXY 1, 2, " °°±±±±±±±±° °°±±±±±±±°° °±±±±±±±±±° °±±±±±±±±±° °±±±±±±±±°° °°±±±±±±±±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 3, " °±± ±° °±± ±±° °± ± ±° °± ± ±° °± ±±° °±± ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 4, " °± ÛÛÛÛ ±° °± ÛÛÛ ±° °± Û ± Û ±° °± Û Û ±° °± ÛÛÛÛ ±° °± ÛÛÛÛ ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 5, " °± Û ±° °± Û Û ±° °± Û ± Û ±° °± ÛÛ Û ±° °± Û Û ±° °± Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 6, " °± ÛÛÛ ±° °± Û Û ±° °± Û ± Û ±° °± Û Û Û ±° °± Û Û ±° °± ÛÛÛ ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 7, " °± Û ±° °± Û Û ±° °± Û Û ±° °± Û ÛÛ ±° °± Û Û ±° °± Û ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 8, " °± ÛÛÛÛ ±° °± ÛÛÛ ±° °± ÛÛÛ ±° °± Û Û ±° °± ÛÛÛÛ ±° °± ÛÛÛÛ ±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 9, " °± ±±° °±± ±±° °±± ±±° °± ± ±° °± ±±° °± ±±° ", 77,

BLUE_B

WRITE_STRINGXY 1, 10, " °±±±±±±±±°° °°±±±±±±±°° °°±±±±±±±°° °±±±±±±±±±° °±±±±±±±±°° °±±±±±±±±°° ", 77,

BLUE_B

WRITE_STRINGXY 1, 11, " °°°°°°°°°° °°°°°°°°° °°°°°°°°° °°°°°°°°°°° °°°°°°°°°° °°°°°°°°°° ", 77,

BLUE_B

WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " Simple Wavelength Player! Just type (0-9) To play a desired tone! ", 77,

WHITE

WRITE_STRINGXY 1, 14, " 1 = C (Frequency 494) ", 77,

WHITE

84
WRITE_STRINGXY 1, 15, " 2 = D (Frequency 440) ", 77,

WHITE

WRITE_STRINGXY 1, 16, " 3 = E (Frequency 392) ", 77,

WHITE

WRITE_STRINGXY 1, 17, " 4 = F (Frequency 349) ", 77,

WHITE

WRITE_STRINGXY 1, 18, " 5 = G (Frequency 330) ", 77,

WHITE

WRITE_STRINGXY 1, 19, " 6 = A (Frequency 294) ", 77,

WHITE

WRITE_STRINGXY 1, 20, " 7 = B (Frequency 262) ", 77,

WHITE

WRITE_STRINGXY 1, 21, " 8 = C (Frequency 245) ", 77,

WHITE

WRITE_STRINGXY 1, 22, " 9 = D (Frequency 220) ", 77,

WHITE

WRITE_STRINGXY 1, 23, " 0 = E (Frequency 196) ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press ESC To Ret To Main Menu ", 77,

REVERSE

GOTOXY 58, 24

; ==================== SOME OF THE SETS OF SOUND CODES HERE ARE BORROWED FROM EVENBIT

get_key2:

mov ah,0 ;function 0 - wait for keypress

int 16h ;call ROM BIOS keyboard services

cmp ah,1 ;ESC key pressed?

je exit2 ;yes, so go exit

cmp ah,02h

je tone_1

cmp ah,03h

je tone_2

cmp ah,04h

je tone_3

85
cmp ah,05h

je tone_4

cmp ah,06h

je tone_5

cmp ah,07h

je tone_6

cmp ah,08h

je tone_7

cmp ah,09h

je tone_8

cmp ah,0ah

je tone_9

cmp ah,0bh

je tone_0

;

jmp get_key2 ;go get another keypress

;

exit2:

RET

;

tone_1:

mov ax, 494

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_2:

mov ax, 440

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_3:

mov ax, 392

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_4:

86
mov ax, 349

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_5:

mov ax, 330

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_6:

mov ax, 294

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_7:

mov ax, 262

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_8:

mov ax, 245

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_9:

mov ax, 220

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

tone_0:

mov ax, 196

mov stor, ax

call sounder ;go generate the tone

jmp get_key2 ;go get another keypress

;

87
;****************************************

; Our sub-routines start here.

;****************************************

;

; Generate sound through the PC speaker.

;

sounder:

mov al,10110110b ;load control word

out 43h,al ;send it

mov ax,stor ;tone frequency

out 42h,al ;send LSB

mov al,ah ;move MSB to AL

out 42h,al ;save it

in al,61h ;get port 61 state

or al,00000011b ;turn on speaker

out 61h,al ;speaker on now

call delay ;go pause a little bit

and al,11111100b ;clear speaker enable

out 61h,al ;speaker off now

; call clr_keyb ;go clear the keyboard buffer

RET ;Ret to caller

delay:

mov ah,00h ;function 0 - get system timer tick

int 01Ah ;call ROM BIOS time-of-day services

add dx,4 ;add our delay value to DX

mov bx,dx ;store result in BX

pozz:

int 01Ah ;call ROM BIOS time-of-day services

cmp dx,bx ;has the delay duration passed?

jl pozz ;no, so go check again

RET ;Ret to caller

; Clear the keyboard buffer.

clr_keyb:

push es ;preserve ES

88
push di ;preserve DI

mov ax,40h ;BIOS segment in AX

mov es,ax ;transfer to ES

mov ax,1Ah ;keyboard head pointer in AX

mov di,ax ;transfer to DI

mov ax,1Eh ;keyboard buffer start in AX

mov es: word ptr [di],ax ;transfer to head pointer

inc di ;bump pointer to...

inc di ;...keyboard tail pointer

mov es: word ptr [di],ax ;transfer to tail pointer

pop di ;restore DI

pop es ;restore ES

RET ;Ret to caller

; ==================== GRAPHICS

GRAPHICS:

CLRSCR

WRITE_STRINGXY 1, 1, " °°°°°°°°°°°°°°°°°°°° °°°°°°°°° °°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°", 77,

BLUE_B

WRITE_STRINGXY 1, 2, "°°±±±±±±±±°°±±±±±±±±°°°°±±±±±±±°°°±±±±±±±±°°°±±±±±±±±±°°±±±±±±±±±°°°±±±±±±±±°", 77,

BLUE_B

WRITE_STRINGXY 1, 3, "°±± ±°°± ±±°°±± ±±°°± ±±°°± ± ±°°± ±°°±± ±°", 77,

BLUE_B

WRITE_STRINGXY 1, 4, "°± ÛÛÛÛ ±°°± ÛÛÛÛ ±°°± ÛÛÛ ±°°± ÛÛÛÛ ±°°± Û ± Û ±°°± ÛÛÛÛÛ ±°°± ÛÛÛÛ ±°", 77,

BLUE_B

WRITE_STRINGXY 1, 5, "°± Û ±°°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û ±°°± Û ±°", 77,

BLUE_B

WRITE_STRINGXY 1, 6, "°± Û ÛÛÛ ±°°± ÛÛÛÛ ±°°± ÛÛÛÛÛ ±°°± ÛÛÛÛ ±°°± ÛÛÛÛÛ ±°°±±± Û ±±±°°± Û ±±±±±°", 77,

BLUE_B

WRITE_STRINGXY 1, 7, "°± Û Û ±°°± Û Û ±°°± Û Û ±°°± Û ±±°°± Û Û ±°°± Û ±°°± Û ±°", 77,

BLUE_B

WRITE_STRINGXY 1, 8, "°± ÛÛÛ ±°°± Û Û ±°°± Û ± Û ±°°± Û ±±±±°°°± Û ± Û ±°°± ÛÛÛÛÛ ±°°± ÛÛÛÛ ±°", 77,

BLUE_B

WRITE_STRINGXY 1, 9, "°±± ±±°°± ± ±°°± ± ±°°± ±°°°° °± ± ±°°± ±°°±± ±°", 77,

BLUE_B

89
WRITE_STRINGXY 1, 10, "°°±±±±±±±°°°±±±±±±±±±°°±±±±±±±±±°°±±±±±° °±±±±±±±±±°°±±±±±±±±±°°°±±±±±±±±°", 77,

BLUE_B

WRITE_STRINGXY 1, 11, " °°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°", 77,

BLUE_B

WRITE_STRINGXY 1, 12, " ", 77,

WHITE

WRITE_STRINGXY 1, 13, " ", 77,

WHITE

WRITE_STRINGXY 1, 14, " ", 77,

WHITE

WRITE_STRINGXY 1, 15, " ", 77,

WHITE

WRITE_STRINGXY 1, 16, " ", 77,

WHITE

WRITE_STRINGXY 1, 17, " Press ANY KEY To Go to Video Mode... ", 77,

WHITE

WRITE_STRINGXY 1, 18, " ", 77,

WHITE

WRITE_STRINGXY 1, 19, " ", 77,

WHITE

WRITE_STRINGXY 1, 20, " ", 77,

WHITE

WRITE_STRINGXY 1, 21, " ", 77,

WHITE

WRITE_STRINGXY 1, 22, " ", 77,

WHITE

WRITE_STRINGXY 1, 23, " ", 77,

WHITE

WRITE_STRINGXY 1, 24, " Press ANY KEY To Go to Video Mode ", 77,

REVERSE

GOTOXY 58, 24

GET_KEYSTROKE

; ==================== SOME OF THE SETS OF SOUND CODES HERE ARE BORROWED FROM RALPH

90
SAVE_REGISTER

;==============================

; Draws a horiz and vert line

;==============================

;==============================

SET_VIDEO_MODE 13h

;=============================

horiz:

mov es, startaddr ;put segment address in es

mov di, 32000 ;row 101 (320 * 100)

add di, 75 ;column 76

mov al,colour ;cannot do mem-mem copy so use reg

mov cx, 160 ;loop counter

hplot:

mov es:[di],al ;set pixel to colour

inc di ;move to next pixel

loop hplot

vert:

mov di, 16000 ;row 51 (320 * 50)

add di, 160 ;column 161

mov cx, 100 ;loop counter

vplot:

mov es:[di],al

add di, 320 ;mov down a pixel

loop vplot

;=============================

GET_KEYSTROKE

SET_VIDEO_MODE 03h

RESTORE_REGISTER

RET

EXIT:

CLRSCR

TERMINATE_PROGRAM

END MAIN

91
END

Whoa! So many? I‟ll give you a tip, “Good programs are not made overnight”. Actually, I‟ve made this

source code for about 1 week of non-stop coding. Don‟t think big, think small first, then let your program

grow. Ok, enough with the lecture let‟s go on learn stuffs.

A. Macros

Macros are much like sub-routines, but they are NOT are actually it! Take this example:

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

STR1 DB "ASSEMBLY LANGUAGE$"

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

MOV BH, 0

MOV DH, 12

MOV DL, 30

INT 10H

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

92
MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

INT 20H

END MAIN

END

This would output three “ASSEMBLY LANGUAGE” message. So if you want to apply macros,

it would look like this:

SHOW MACRO

MOV AH, 09H

MOV DX, OFFSET STR1

INT 21H

ENDM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

STR1 DB "ASSEMBLY LANGUAGE$"

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

93
MOV BH, 0

MOV DH, 12

MOV DL, 30

INT 10H

SHOW

SHOW

SHOW

INT 20H

END MAIN

END

See? The source codes are quite now shorter. Macros combines those commands into single

command, but actually, if you compile them the compiler will replace again the macro commands

into actual codes again, thus making the un-macroed and macroed source codes have same

executable file size. Again, macros are not procedures, what my point? If you rely heavily on

macros (also with nested macros) you might have a “Insufficient Memory” problem, that‟s why

my other BIG macros where rendered useless =( . Also it‟s a big headache in debugging, because

the debugger will render the macro as a single code and NOT as a procedure that the debugger

would also check into. Ok, so, our syntax (for this meantime) for macros is this:

<NAME> MACRO

<CODES HERE>

ENDM

Ok now let‟s move on! Let‟s try putting some parameters. Check this out:

94
; ==================== GOTOXY

GOTOXY MACRO X,Y

MOV AH, 02H

MOV DH, Y

MOV DL, X

INT 10h

ENDM

So if I typed “GOTOXY 12, 12”, it will go column 12, row 12. So this is the syntax of macro:

<NAME> MACRO <PARAMETERS>

<CODES HERE>

ENDM

Still digesting the macro commands? Ok, this is the last lesson about macros. You might think on

making labels on macros like this:

; ==================== PRINTF

PRINTF MACRO STRING

MAIN: JMP START

VAR DB STRING,'$'

START:

95
MOV AH, 09h

MOV DX, OFFSET VAR

INT 21h

ENDM

But actually the compiler will make an error that is not accepted, why? Take this theory, suppose

your whole program would look like this:

; ==================== PRINTF

PRINTF MACRO STRING

MAIN: JMP START

VAR DB STRING,'$'

START:

MOV AH, 09h

MOV DX, OFFSET VAR

INT 21h

ENDM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

MOV BH, 0

96
MOV DH, 12

MOV DL, 30

INT 10H

PRINTF “ASSEMBLY LANGUAGE”

INT 20H

END MAIN

END

Remember the macro ONLY combines multiple codes into one single code, so the compiler

would see this code as this:

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

START:

MOV AX, 03H

INT 10H

MOV AH, 02H

MOV BH, 0

MOV DH, 12

MOV DL, 30

INT 10H

MAIN: JMP START

VAR DB “ASSEMBLY LANGUAGE”,'$'

START:

MOV AH, 09h

97
MOV DX, OFFSET VAR

INT 21h

INT 20H

END MAIN

END

You see the problem? It has two “START labels” where the “JMP START” would go? And this

would lead into confusion. And that‟s why label are not allowed inside macros, unless you have

the right thing to do it. To make labels on macros use LOCAL, look at this example:

; ==================== PRINTF

PRINTF MACRO STRING

LOCAL MAIN, START, VAR

MAIN: JMP START

VAR DB STRING,'$'

START:

MOV AH, 09h

MOV DX, OFFSET VAR

INT 21h

ENDM

98
This won‟t make any conflict with other labels or variables that has the same name of it. LOCAL

means it renders the variables and labels to be inclusively available on the macro. Ok, now take

your time to digest everything that we studied about macros. =)

B. CMP, JMP Commands

Ok let‟s continue. CMP and JMP commands are used in program control flow; it tells the program

where to go next. Actually JMP has many flavors like JNE, JE, and many, many more. But we

will only concentrate at that two only. Take this example:

CMP CHARACTER2, 'A'

JE BIG_A

First, it will compare (CMP) “CHARACTER2” with character „A‟. Second, if it is identical, it

will jump (JE) the label “BIG_A”. Only reminder, you can only jump at short distances. The other

twin brother of JE is JNE, which means Jump If Not Equal.

C. Get Keystrokes (GETCH)

This is usually used for pause. These are the codes:

MOV AX,0000h

INT 16h

99
D. PUSH & POP

PUSH usually “pushes” the current data into the stack, and actually you can PUSH more. While

on POPPING, the last data that you PUSHED will be POPPED first. Take this example:

PUSH AX

PUSH BX

PUSH CX

PUSH DX

This stores all the current values of the registers into the stack. Then it can be reclaimed again by

typing this:

POP AX

POP BX

POP CX

POP DX

E. EQU Command

EQU command renders one thing into another thing. For example:

RED EQU 00000100B

100
It is harder to memorize the red value in binary form (00000100B), but it is easier to memorize it

in word form. So the syntax would be this:

<NAME> EQU <EQUIVALENT>

F. Colored & Blinking Text (CPRINTF)

Now, let‟s have some REAL programming. We only have a function for colored character and not

colored string and that is INT 10 Function 09H. Try this:

MOV AH, 09h

MOV BL, 1

MOV AL, „A‟

INT 10h

Executing this command shows a blue colored letter „A‟. And this is the syntax:

MOV AH, 09h

MOV BL, <COLOR>

MOV AL, <CHARACTER>

INT 10h

Just remember when typing the character; always enclose it with a single quote. For greater

control on the characters, try using binaries. Here‟s the syntax:

101
0 – Make it Blinking

0 – Make the background color Red

0 – Make the background color Green

0 – Make the background color Blue

0 – Make the foreground color Intensified

0 – Make the foreground color Red

0 – Make the foreground color Green

0 – Make the foreground color Blue

B – This signifies that it‟s a Binary

For example, you want to make a Blinking Text, with Red background, and Green Foreground:

MOV BL, 11000010B

NOTE: If you didn‟t include the „B‟, it will be automatically rendered as Decimal.

Now, but we want to make colored string and not just colored characters. Well I have the macro

which fits right for you:

; ==================== CPRINTF

CPRINTF MACRO STRING, STRING_SIZE, COLOR

LOCAL MAIN, START, VAR, LOOP_LABEL

102
MAIN: JMP START

VAR DB STRING,'$'

START:

MOV AH, 09h

MOV BH, 0

MOV BL, COLOR

MOV SI, OFFSET VAR

ADD SI, STRING_SIZE

MOV CX, STRING_SIZE

DEC SI

LOOP_LABEL:

MOV AL, [SI]

INT 10h

DEC SI

LOOP LOOP_LABEL

ENDM

The syntax for this is:

CPRINTF <STRING>, <STRING_SIZE>, <COLOR>

G. Sounds

103
Ok, let‟s go to sounds, I got a piece of source from my sample code to examine:

sounder:

mov al,10110110b ;load control word

out 43h,al ;send it

mov ax,stor ;tone frequency

out 42h,al ;send LSB

mov al,ah ;move MSB to AL

out 42h,al ;save it

in al,61h ;get port 61 state

or al,00000011b ;turn on speaker

out 61h,al ;speaker on now

and al,11111100b ;clear speaker enable

out 61h,al ;speaker off now

RET ;Ret to caller

The variable STOR is where we stored the frequency. Now we will study about IN and OUT, IN

and OUT is used in ports, where IN is getting something from the port while OUT is putting

something in the port. The port 43H has some controls about the speaker, and port 42H is where

we put the frequency of the program, and the port 61H is where we turn on and off the program.

You can put a delay code in-between the opening and closing of the speaker to hear the desired

duration.

104
Ok, this is what happened to that code: First, the control word (10110110B) was sent to port 43H

to initialize the Speaker, then the frequency was sent to port 42H, sending the lower significant

byte (LSB) first and then the most significant byte (MSB). Then, it gets the state of port 61H, and

then opens the speaker, and then turns it off. For more information about ports, check the Internet

for it.

H. Graphics

This is the favorite of everyone, but this is the most hard. Ok, now, first we need to get to the

video mode, to get there we to use this syntax:

MOV AH, 00H

MOV AL, <MODE>

INT 10h

Let‟s use 13H Mode. It‟s has 320 x 480 resolution and it‟s colored. Now where in the Video

Mode, now we can draw graphics. We‟ll be using Video Memory, it‟s quite hard to understand

but it runs faster than the traditional way. Now let‟s start understanding some piece of codes:

mov es, 0A000H ;put segment address in es

mov di, 32000 ;row 101 (320 * 100)

mov al, colour ;cannot do mem-mem copy so use reg

mov es:[di], al ;set pixel to colour

105
The segment that we need to use is ES or the Extra Segment, with the address of 0A000H. The DI

is where you point the pixel into the screen. The coordinates are quite confusing, but here it is: DI

0 is located at the Upper Left most side of the screen. When you put DI with 320 it will be in the

Upper Right most side of the screen. But when you make your DI 321, it will be in the left most

part of the screen, only it is in the second row. Again, if your DI is 640 it will be in the far right of

the screen and on the second row, but if you put DI 641 it will be again on the far left but rather in

the third row and so on, and so fourth. Gets? I hope you got it =) Now, I that code the syntax

would be:

MOV ES, 0A000H

MOV DI, <COORDINATE>

MOV AL, <COLOR>

MOV ES:[DI], AL

106
IV. PEX: A CLOSER LOOK AT DB

Try typing this:

PREX.ASM

; FILENAME : PREX2.ASM
; AUTHOR : MELJUN P. CORTES
; PROFESSOR : MELJUN P. CORTES

.MODEL TINY
.CODE
ORG 0100H

MAIN:
JMP START

; ========== VARIABLE DECLARATION ==========
STRING1 DB "Enter Your Name: $"
STRING3 DB "HELLO $"
STRING2 DB 30,?,29 DUP(?)

START:
; =========== CLEARS THE SCREEN
MOV AX, 03H
INT 10H

; =========== SHOW "ENTER YOUR NAME"
MOV AH, 09H
MOV DX, OFFSET STRING1
INT 21H

; =========== ASK THE NAME
MOV AH, 0AH
MOV DX, OFFSET STRING2
INT 21H

; =========== GOTOXY TO THE NEXT LINE
MOV AH, 02H
MOV DL, 0
MOV DH, 2
INT 10H

; =========== SHOW THE RESPONSE
MOV AH, 09H
MOV DX, OFFSET STRING3
INT 21H

MOV AH, 09H
MOV DX, OFFSET STRING2
INT 21H

;=========== TERMINATE THE PROGRAM
INT 20H
END MAIN
MAIN

107
You will notice that it prints garbage, unless you put „$‟ on your input. And even you put a dollar sign at

the input you will see two garbage characters at front. This is what really happened: The INT

21H/AH=09H function needs three things, the first character should be the size of the variable, the second

character is how many characters you typed, and the third is the actual buffer. That‟s why, it prints to

“symbolic” characters before the actual input (or name), and because it didn‟t encountered a dollar sign, it

will print “memory contents” until it encountered a dollar sign. Ok, let‟s solve this one-by-one: To

remove the two symbols at first we need to move the offset by two. Look at this: Instead of this:

MOV DX, OFFSET STRING2

Try this:

MOV DX, OFFSET STRING2 + 2

Next, to stop the function from printing memory contents, we must add a dollar sign. Try this: Instead of

this:

STRING2 DB 30,?,29 DUP(?)

Try this:

STRING2 DB 30,?,29 DUP(„$‟)

108
V. MP3: ASCII Code Handling

On you third MP, we were told to make a program that prints our name WITHOUT using and DB, just

merely using ASCII Code values, but adding it or subtracting it. To get a better view, take a look of my

code:

PMCMP3.ASM

; PROGRAM NAME : PMCMP3.ASM

; PROGRAMMED BY: MELJUN P. CORTES

; DATE STARTED : NOVEMBER 10, 2005

; DATE FINISHED: _____________________

;========================= THE MACROS ========================================

PRINTF MACRO

MOV AH, 02H

INT 21H

ENDM

;========================= THE MAIN PROGRAM ==================================

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

START:

; =============== CLEARS THE SCREEN

MOV AX, 03H

INT 10H

109
;P

MOV DL, 80

PRINTF

;A

SUB DL, 15

PRINTF

;U

ADD DL, 20

PRINTF

;L

SUB DL, 9

PRINTF

;

SUB DL, 44

PRINTF

;M

ADD DL, 45

PRINTF

;A

SUB DL, 12

PRINTF

;R

ADD DL, 17

PRINTF

;K

SUB DL, 7

PRINTF

110
;

SUB DL, 43

PRINTF

;D

ADD DL, 36

PRINTF

;E

ADD DL, 1

PRINTF

;

SUB DL, 37

PRINTF

;M

ADD DL, 45

PRINTF

;E

SUB DL, 8

PRINTF

;S

ADD DL, 14

PRINTF

;A

SUB DL, 18

PRINTF

;

SUB DL, 33

PRINTF

111
;C

ADD DL, 35

PRINTF

;A

SUB DL, 2

PRINTF

;S

ADD DL, 18

PRINTF

;T

ADD DL, 1

PRINTF

;I

SUB DL, 11

PRINTF

;L

ADD DL, 3

PRINTF

;L

PRINTF

;O

ADD DL, 3

PRINTF

INT 20H ; Terminates the program

END MAIN ; End the MAIN Procedure

END ; End the whole code

112
Ok, now I‟ll introduce you into one more function, and that is PUTC, check this example:

MOV AH, 02H

MOV DL, 80

INT 21H

This would output a letter „P‟ on screen. The DL is where you put the character OR the character value,

the character value of P is 80 so you could make your code like this:

MOV AH, 02H

MOV DL, „P‟

INT 21H

You might ask, “What if I want to output the number 9 and NOT the character value of 9?” The answer to

is, if your want a character value, just put the number but if you want just the character, just enclose it

with single quote. Check this code for a better view:

MOV AH, 02H

MOV DL, „P‟

INT 21H

So the syntax of PUTC would be this:

MOV AH, 02H

113
MOV DL, <CHARACTER OR CHARACTER VALUE>

INT 21H

This code would output my full name: “PAUL MARK DE MESA CASTILLO”. Notice my first value of

DL is 80, and that is letter „P‟ on the ASCII Code. Then I just add and subtract the value of DL to get the

desired output. Just check the ASCII Code Table for more information:

114
VI. MORE EXAMPLES: MEMORY HANDLING

A. Exercise 1

These are not our MPs, but it is substantial to our learning. Take a look at this code:

MIDEXER.ASM

CLRSCR MACRO

MOV AX, 03H

INT 10H

ENDM

PRINT MACRO PARAM

MOV AH, 02H

MOV DL, [PARAM]

INT 21H

ENDM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

STR1 DB "I'D_Never_Loved_This_Way_Again$"

115
STR2 DB "I don't wanna miss a thing$"

START:

CLRSCR

MOV BX, OFFSET STR1 + 10

MOV SI, OFFSET STR2 + 7

MOV DI, OFFSET STR2

PRINT SI

INC SI

DEC BX

ADD DI, 7

PRINT BX

ADD DI, 7

PRINT SI

PRINT DI

INT 20H

END MAIN

END

Just think, if you typed: “MOV DX, OFFSET <VARIABLE>” The first memory location would

be stored in DX. Ok let‟s go to theory to explain it further. You typed:

STR DB “PAUL$”

116
Let‟s assume the letter „P‟ was store at memory location 100 then „A‟ is memory location 101,

and so on and so forth. So if you typed:

MOV DX, OFFSET STR

The value of DX would be 100. Ok, now, so if you typed:

MOV DX, OFFSET STR + 2

The compiler would at it like this:

MOV DX, 100 + 2

So the value of DX is the memory location 102 which is „U‟. And if you typed:

INC DX

The INC “increases” (actually the right term is “increment”) by one so, DX + 1, the answer is 103,

and that would be „L‟. The counter part of INC is DEC which subtracts by one.

117
B. Exercise 2

FINALS.ASM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

VAR1 DB "happy_foundation_day!!!$"

VAR2 DB "1234567890$"

VAR3 DB "MAY_THE_GOOD_LORD_BLESSed_US!! $"

START:

MOV AX, 03H

INT 10H

MOV BX, OFFSET VAR3

MOV SI, OFFSET VAR2

MOV BP, OFFSET VAR1 + 6

MOV CX, 6

JECOY:

DEC BP

INC SI

MOV AH, 02

MOV DL, [SI]

INT 21H

MOV AH, 02

MOV DL, [BP]

INT 21H

118
ADD BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

LOOP JECOY

MOV CX, 5

JBL:

INC BX

MOV AH, 02

MOV DL, [BX]

INT 21H

LOOP JBL

INT 20H

END MAIN

END

This now introduces to looping. Ok, the things that are need to looping are the register CX and the

command LOOP. Every loop decreases the value of CX until it is zero. Check this example:

MOV CX, 5

LOOP_LABEL:

MOV AH, 02H

119
MOV DL, „P‟

INT 21H

LOOP LOOP_LABEL

Ok, this would print five „P‟, because the CX was set to 5. The CX is much like CTR on C

language. So the syntax for this would be:

MOV CX, <NUMBER OF LOOPS>

<LABEL NAME>:

<COMMANDS>

LOOP <LABEL NAME>

If you would think, the C language equivalent for this is:

For ( CTR = 5; CTR > 0 ; CTR—)

{

Printf(“P”);

}

C. Exercise 3

FINALS2.ASM

.MODEL TINY

120
.CODE

ORG 0100H

MAIN: JMP START

VAR1 DB "Assembly Language$"

VAR2 DB "THE DOS PROG_LANGUAGES$"

START:

MOV AX, 03

INT 10H

MOV BX, OFFSET VAR2

MOV SI, OFFSET VAR1 + 5

INC BX

ADD SI, 6

ADD BX, 3

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV AH, 02

MOV DL, [SI]

INT 21H

DEC BX

SUB SI, 3

MOV AH, 02

MOV DL, [SI]

INT 21H

ADD BX, 12

SUB SI, 6

121
MOV AH, 02

MOV DL, [SI]

INT 21H

DEC BX

SUB BX, 9

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1 + 2

MOV BX, OFFSET VAR2 + 5

ADD SI, 5

MOV AH, 02

MOV DL, [SI]

INT 21H

SUB BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1 + 2

MOV AH, 02

MOV DL, [SI]

INT 21H

ADD BX, 2

MOV AH, 02

MOV DL, [BX]

122
INT 21H

MOV SI, OFFSET VAR1

MOV AH, 02

MOV DL, [SI]

INT 21H

INT 20H

END MAIN

END

You might ask also, “What‟s the difference of DI and [DI]? Well, DI is the memory LOCATION,

while [DI] is the memory CONTENT. Take this example:

VAR2 DB "THE DOS PROG_LANGUAGES$"

MOV BX, OFFSET VAR2

MOV AH, 02

MOV DL, [BX]

INT 21H

Let‟s presume that the memory location of VAR2 is 100. So this, the value of BX is 100, BUT the

value of [BX] is the letter „T‟. Gets? Ok now my next 2 Exercises are just repeated from the

previous exercises, but it would help you understand Assembly, try getting it output. =)

123
D. Exercise 4

FINALS3.ASM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

VAR1 DB "ABCDEFGHIJKLMNOPQRS$"

VAR2 DB "abcdefghijkljmno$"

VAR3 DB "1234567890$"

START:

MOV AX, 03

INT 10H

MOV BX, OFFSET VAR1

MOV SI, OFFSET VAR2

MOV BP, OFFSET VAR3 + 6

MOV CX, 6

JECOY:

DEC BP

INC SI

MOV AH, 02

MOV DL, [SI]

INT 21H

DEC BX

SUB BX, 9

MOV AH, 02

MOV DL, [BX]

124
INT 21H

MOV SI, OFFSET VAR1 + 2

MOV BX, OFFSET VAR2 + 5

ADD SI, 5

MOV AH, 02

MOV DL, [SI]

INT 21H

SUB BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1 + 2

MOV AH, 02

MOV DL, [SI]

INT 21H

ADD BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1

MOV AH, 02

MOV DL, [SI]

INT 21H

INT 20H

125
END MAIN

END

E. Exercise 5

FINALS4.ASM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

VAR1 DB "what a beautiful day$"

VAR2 DB "WHAT A WONDERFUL LORD$"

START:

MOV AX, 03

INT 10H

MOV BX, OFFSET VAR2

MOV SI, OFFSET VAR1 + 5

INC BX

ADD SI, 6

ADD BX, 3

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV AH, 02

MOV DL, [SI]

INT 21H

126
DEC BX

SUB SI, 3

MOV AH, 02

MOV DL, [SI]

INT 21H

ADD BX, 12

SUB SI, 6

MOV AH, 02

MOV DL, [SI]

INT 21H

DEC BX

SUB BX, 9

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1 + 2

MOV BX, OFFSET VAR2 + 5

ADD SI, 5

MOV AH, 02

MOV DL, [SI]

INT 21H

SUB BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

127
MOV SI, OFFSET VAR1 + 2

MOV AH, 02

MOV DL, [SI]

INT 21H

ADD BX, 2

MOV AH, 02

MOV DL, [BX]

INT 21H

MOV SI, OFFSET VAR1

MOV AH, 02

MOV DL, [SI]

INT 21H

INT 20H

END MAIN

END

F. Exercise 6

FINEXER.ASM

.MODEL TINY

.CODE

ORG 0100H

MAIN: JMP START

V1 DB " MELJUN P. CORTES $"

128
START:

MOV AX, 03H

INT 10H

MOV DI, OFFSET V1 + 15

MOV CX, 3

X:

PUSH CX

MOV AH, 02

MOV DL, [DI]

INT 21H

MOV CX, 2

Y:

MOV AL, [DI]

DEC DI

MOV AH, 2

MOV DL, AL

INT 21H

LOOP Y

POP CX

LOOP X

INT 20H

END MAIN

END

129
PERSONAL NOTES FROM THE AUTHORS

I was asked, "Why do these? You can still pass without ever doing to this and still have a good grade."

But I'm not doing this anymore for grades; I'm doing this for a personal reason:

For me:

Knowledge is far greater than fame;

Knowledge is far greater than money; and

Knowledge is far greater than grades.

That‟s why we can proudly say, we made this manual. Nothing where “copy-pasted”, everything was

made by just by our mere hands, hearts, and minds.

I came from the line of publishers. My parents are both book worms, that‟s why if you would visit our

house it's much like a library, and both my parents are publishers. My father is also a good layoutist,

which I inherited from him. And my mother is a English teacher, that's why she is a good proofreader,

that's why I consult to her for my grammar and spelling.

"To be a good leader, you must be a good follower". It was my childhood desire about computers. I've

read a lot of computer books; books that helped me increase my knowledge about computers and also

increased my vocabulary. As I read many computer books, I've noticed something, they are too cryptic to

understand, and how can an ordinary person understand this? For me knowledge is for everyone, there is

130
no need for "highly resounding words" or "overly technical words" or "confusing theories". I want to

make me own book, I want to make a book that everyone could be easily understand, I want to make a

book that is short and simple, and I want to make a book that is fun to read. I want to make a book.

Long, long time ago, I've been planning how to make a book: From the layout of the book to the

copyrighting of the book. And I amassed a great number of books, I made layouts on my scratch pad, and

I asked many people how to copyright a book. And now, everything that I've planned is now being put

into practice. Some think it's a burden, but for me it's an challenge, a challenge to reach my goals and

aspirations.

One of our first success is the documentation about Prolog that has about 200 Pages. The success told us,

that we can really make a book and shine. Another reason why I want to make a book it that, persons may

fade but books won't. I've read many good books whose authors have already "faded", but it seems they

are still alive, and still helping others. That's why I want my every publications that I made would benefit

on the next generations to come. (Personal Notes: Sir! Sana Sir pag nakita nyo po etong gawa namin ulit

maalala nyo kami ha!)

Now, on this new publication, due to lack of enough time, I want to ask for apology, that‟s why we‟ve

just concentrated on the laboratory manual, because “application is better than theory”. This book is

much like a "Diary of what we learned". We‟ve divided this manual according to our MPs (Machine

Problems) made when we are studying Assembly Language, explaining Assembly step-by-step. The

examples here are from actual laboratory activities that we made. Most of the parts of this manuals have

C “ancestry”, so for C programmers, it is easier to study this. You might also notice that the source codes

131
are quite small in font, this is because for you to see it better in this short paper width. My principle of

teaching is by example, so this would be filled with examples.

First of all, I want to give all the blessings back to God for helping even since the project began. I also

want to give thanks to my parents for supporting us in our project and from them where my skills where

inherited. We also want to give thanks to our Team Leader for his hard-work and dedication for our

project, and also our teammates for their teamwork and cooperation. We also want to give thanks to our

classmates, the class CA, for being there in our rough times. And last and but not the least, we want to

give thanks to our professor, Prof. Pepito, Copernacus, for his excellence, dedication, and patience in

teaching us.

MELJUN P. CORTES

132