You are on page 1of 27

INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING

History of assembly language programming

Early computer systems were basically programmed by hand. The front panel switches were
used to enter instructions and data. These switches are represented the address, data and
control lines of the computer system. To enter the data into memory, the address switches
were toggled to the correct address, the data switches were toggled next, and finally the
control lines switch was toggled. This wrote the binary value on the front panel data
switches to the address specified. Once all the data and instruction were entered, the run
switch was toggled to run the program.

The programmer also needed to know the instruction set of the processor. Each instruction
needed to be manually converted into bit patterns by the programmer so that the front
panel switches could be set correctly. This led to errors in translation as the programmer
could easily misread 8 as the value B. It became obvious that such methods were slow and
error prone.

With the arrival of better hardware which could address larger memory, and the increase in
memory size (due to better production techniques and lower cost), programs were written
to perform some of this manual entry. Small monitor programs became popular, which
allowed entry of instructions and data via hex keypads or terminals. Additional devices such
as paper tape and punched cards became popular as storage methods for programs.

The programs were still programmed by hand, in that the conversion from mnemonics to
instructions was still performed manually. To increase programmer productivity, the idea of
writing a program to interpret another was a major breakthrough. This would be run by the
computer, and translate the actual mnemonics into instructions.

As programmers were writing the source code in mnemonics, it seemed the logical next
step. The source file was fed as input into the program, which translated the mnemonics
into instructions, then wrote the output to the desired place (etc. paper-tape). This
sequence is now accepted as a common place. The only advances have been the increasing
use of high level languages to increase programmer productivity.

1
Introduction

Assembly language represents each of the many operations that the computer can do with a
mnemonic, a short series of letters, using as assembler to convert these mnemonics into
actual processor instructions and associated data.

Assemblers are programs which generate the machine code instructions from a source code
program written in assembly language. Some of the features provided by an assembler are:

 allows the programmer to use mnemonics when writing source code


 symbolic code is easier to read and follow
 error checking is provided
 changes can be quickly and easily incorporated with a re-assembly

Typically, an assembler reads a file of assembly language and translates it one line at a
time, outputting a file of machine language. The input file is called the „source file‟ and the
output file is called the „object file‟. The machine language patterns produced are called the
„object code‟.

Also produced during the assembly process is a „listing‟, which summarizes the results of the
assembly process. In the event that the assembler was unable to understand any of the
source lines, it inserts error message in the listing, pointing out the problem.

This project is to construct a program for counting the number of sentences and
paragraphs. In this program, the input file and the program file must be in the same
location as all the assembly and exe file. The program is started with no number insertion
prompted out that asked user to key in. The program will be run and the result obtained
from the program is integer for sentences and paragraphs.

FUNDAMENTAL STUDY
To successfully carry out the project, some fundamental knowledge on program design r=is
required. Below are the elaborations of the task that need to be included in constructing a
program.

2
2.1. Design Stage

The design stage involves expressing the solution to the problem in a standard format.
There are several design tools (pseudo-language) that can be used by the programmer. The
most common design tool used by assembly language programmer is a flowchart. While,
pseudo code is common design tool used by third and fourth generation programmers.
These common design tools are briefly described below:

2.1.1. Flowchart

Flowchart is a graphical representation of the program logic. It is one of the oldest methods
of program logic. It is one of the oldest methods of program design. Flowchart uses
graphical shapes to represent different actions that actions that the computer will perform.
Arrow that indicates the flow of control connects these shapes.

2.1.2. Coding

A written computer instruction is called a code and the process of writing codes is called
coding. The code written by programmers is called source code. The programmer then uses
a compiler to compile the source code to produce what is called an object code. The object
code is then converted to a program that is ready to run which is called executable code or
machine code.

2.1.3. Debugging

A bug is an error or defect in a software or hardware that causes a program to malfunction.


The process of detecting and removing bugs is called debugging; this process is an iterative
process that is carried out every time an error is detected by the testing stage. Thus the
debugging stage may involve going back through the analysis, design, coding and testing
stages.

2.2. Coding for Program

1. Model Small

MODEL ONLY needs to be used for simplified segments. Code & Data have separate
segment, but must be each less than 64k Both Code and Data are NEAR. For most
applications, this will suffice.

3
2. .Stack 200h

Tells the compiler to set up a 200h byte stack upon execution of the program. NOTE: the
size you choose for the stack does not change the size of the file on disk. You can see what
I mean by changing the 200h to, say, 400h and then recompiling. The file sizes are
identical. This could be replaced with:

: MyStack SEGMENT PARA PUBLIC STACK 'STACK'

: db 200h dup (0)

: MyStack ENDS

BUT, doing it this way makes your executable 512 bytes bigger. If you were to double to
400h, the executable would be another 512 bytes bigger. I think it's pretty obvious why the
simplified version is preferred.

3. Data

Is the place to declare the entire required variable in the program. For a normal usage of program,
WORD or BYTE could have been used.

START:

The label of starting a program. Mostly all the program will be written under Start.

4. End Start

This tells the compiler that we are all done with our program and that it can stop compiling,
now.
5. The INT, INTO, BOUND, and IRET Instructions

The int (for software interrupt) instruction is a very special form of a call instruction.
Whereas the call instruction calls subroutines within your program, the int instruction calls
system routines and other special subroutines. The major difference between interrupt
serviceroutines and standard procedures is that you can have any number of different
procedures in an assembly language program, while the system supports a maximum of 256
different interrupt service routines. A program calls a subroutine by specifying the address of
that subroutine; it calls an interrupt service routine by specifying the interrupt number for

4
that particular interrupt service routine. This chapter will only describe how to call an
interrupt service routine using the int, into, and bound instructions, and how to return from
an interrupt service routine using the iret instruction.

6. Data Movement Instructions


The data movement instructions copy values from one location to another. These
instructions include mov, xchg, lds, lea, les, lfs, lgs, lss, push, pusha, pushad, pushf, pushfd,
pop, popa, popad, popf, popfd, lahf, and sahf.

7. Unconditional Jumps
The jmp (jump) instruction unconditionally transfers control to another point in the program.
There are six forms of this instruction: an intersegment/direct jump, two intersegment/
direct jumps, an intersegment/indirect jump, and two intersegment/indirect jumps.
Intersegment jumps are always between statements in the same code segment.
Intersegment jumps can transfer control to a statement in a different code segment. These
instructions generally use the same syntax; it is jmp target the assembler differentiates
them by their operands.

8. The CMP Instruction


The cmp (compare) instruction is identical to the sub instruction with one crucial difference
– it does not store the difference back into the destination operand.

9. The Conditional Jump Instructions

Although the jmp, call, and ret instructions provide transfer of control, they do not allow you
to make any serious decisions. The 80x86‟s conditional jump instructions handle this task.
The conditional jump instructions are the basic tool for creating loops and other conditionally
executable statements like the if..then statement. The conditional jumps test one or more
flags in the flags register to see if they match some particular pattern (just like the setcc
instructions). If the pattern matches, control transfers to the target location. If the match
fails, the CPU ignores the conditional jump and execution continues with the next
.

5
PROBLEM STATEMENT
Create a program for counting the number of sentences and paragraphs.

PROGRAM OBJECTIVES
With the given problem statement, several main objectives or functions of the
program are outlined before attempting to write the source code. The basic objectives of
this program are listed as follow:

Read a text file (.txt) and load the texts into data registers
Read the data character by character to count the occurrences of periods.
Read the data character by character to count the occurrences of „carriage return‟ or
in ASCII code, „0Dh‟.
Print and display the results.

DESIGN STAGE
3.1 Design Considerations

The first attempts of producing the program are by identifying all the functions that
the program should perform in order to solve the stated problem. Hence, the program‟s
design considerations are initially listed as shown below:

Read a separate text file for data and store in data registers as a string for further
operations.
Since every end of a sentence must be followed by a period or full stop „.‟, therefore
the program design should detect the occurrences of periods in the text file.
A „sentence counter‟ is created to count and store the number of occurrences of
periods, or similarly, the number of sentences.
Generally, a new paragraph always begin in a „new line‟, hence the program should
be able to detect the occurrences of „new line‟ input through the keyboard‟s Enter
key or ASCII code, „0Dh‟.
Another counter is created to count the occurrences of „new line‟ inputs in the text
file.
The results of the both counters are then printed and displayed on the command
prompt window.

3.2 Flowcharts

A flowchart is defined as a graphical representation of the program logic and it is one


to the oldest methods of program design. While psuedocode is also widely used for
programming structure building but commonly used for third and fourth generation
programming. For the purpose of designing this program, three flowcharts are drawn to
show the flow of the desired program. Firstly, the two functions of counting sentences and
paragraphs are designed as two separate programs thus two separate flowcharts are
created as shown in figure 1 and figure 2.

6
7
8
9
Figure 1 shows a program process flow for counting the number sentences from the
input file. As the program is executed, it will begin by opening the designated input text file.
If it is successfully opened, the program continues to read the contents of the text file and
load them into data registers as strings. In the event of error reading the file, the program
will return an error message and it is terminated immediately.
The program counts the number of bytes of data from the input file then reads the
first character and decides if the character is a dot, question mark or exclamation mark
character. If no, a loop is used to restart the process and read the next character. If yes,
the counter increase count by 1 and the process is looped to read the next character. The
process will repeat looping until no more character is detected in the string. Subsequently,
the total counts by the counter will be printed to be seen by the user on the command
prompt window.

Figure 2 shows another individual program to count the occurrences of „new line‟
inputs. The only difference is that this read the data for ASCII code input „0Dh‟.
Figure 3 is another flowchart that integrates both counting procedures of sentences
and paragraphs into one single program. The desired program should run with accordance
to the flow as shown in figure 3 where each character is tested for dot character,
exclamation mark or question mark to count sentences while it also simultaneously test for
ASCII code input „0Dh‟ which is a new line to count paragraphs. Both the results are printed
and displayed after all characters have been read. The program ends after printing the
results.
In order to increase the reliability of the program, an initial procedure is created to
open and read the input text file. This procedure will return an error message such as
„UNABLE TO OPEN FILE‟, „UNABLE TO READ FILE‟ or „UNABLE TO CLOSE FILE‟. On executing
the program, it will locate the designated text file which name is written in the source code.
The file will fail to open in the event that the stated file name is too long or the file name
has been wrongly typed. Upon successfully opening the file, the program will proceed to get
the file handle and then read the data in the file. If the program fails to read the data then it
will print and display an error message and terminate the program. If successful, the
program proceeds to reading the number of bytes of data from the input file and
sequentially activates the counting procedures. After the process has been done, program
will attempt to close the input text file and detects for error in the process. If process has an
error, then error message will be displayed and program is terminated. If no error is
detected then the program ends normally.

3.3 Coding

With the design considerations in mind and using the flowchart as guidelines, a set
of written computer instructions is written using the Notepad software available in any
Microsoft Windows operating systems. After the source code is complete, an assembler has

10
to be used to translate the source code into machine code instructions in an object file that
can be executed by the microprocessor. In this project, the BORLAND TURBO ASSEMBLER is
used.

3.4 Turbo Assembler

The procedures of using the turbo assembler to create an executable file from a set
of source code will be briefly discussed here. The turbo assembler used for the purpose of
this project is a ready-to-use folder package named tasm. The package includes an
assembler, a linker and also a debugger.The steps are as follow:

The source code has to be saved as a .asm file, for example program.asm, and this
file is stored in the „BIN‟ folder in the „tasm‟ folder which is usually kept in the C
drive for ease of access.
The text file to be read is saved as .txt file and is saved in the BIN folder also. In this
demonstration. A text file named test.txt is used and the contents are shown below.

Figure 5: Sample input file saved as test.txt


Using the Microsoft Office‟s built-it counter, the number of sentences is 10 while the
number of paragraphs is 3.
A command prompt window is needed to operate the assembler. The directory is
first changed to the BIN folder. The command line to instruct Turbo Assembler to
assemble a certain .asm file is:
TASM filename.asm

Figure 6: Assembly Command Line and output


After successfully assembled the program, another program called the Linker is used
to link several object files into an executable file that can be executed. The linker

11
comes together in the Turbo Assembler package and the command line to link an
object file is:
TLINK filename.obj

Figure 7: Linking Command Line


If no error or warnings are reported, an executable file is created, name
program.exe and can be executed by entering the program name in the program
line.

Figure 8: PROGRAM.EXE is generated and stored in the BIN folder


Using the dir command in the command prompt will list out all the available files in
the BIN folder and can be use to check for the availability of the executable and the
desired text file which is to be read.

The generated program can be launched by inputting the following command:


program.exe
or simply
program

Figure 9: Executing the program


The program will read the number of sentences and paragraphs and the results
printed as shown in figure 9. The results given by the program is in agreement with
the numbers of sentences and paragraphs initially counted which were 10 sentences
and 3 paragraphs respectively.

12
PROGRAM CODE
.model small

.stack 200h

.data

bufferSize = 5120

buffer db bufferSize dup(?)

bytesRead dw ?

inputFile db "test.txt$"

inputHandle dw ?

outputErrorO db "UNABLE TO OPEN FILE.$"

outputErrorR db "UNABLE TO READ FILE.$"

outputErrorC db "UNABLE TO CLOSE FILE.$"

outputFileName db " FILE LOADED: $"

outputParagraph db 13, 10, " NO OF PARAGRAPHS: $"

outputSentences db 13, 10, " NO OF SENTENCES: $"

countParagraph dw 0

countSentences dw 0

.code

start:

mov ax, @data ; SEGMENT PREPARATIONS FOR


INPUT DATA

mov ds, ax

; HANDLE FILE OPERATION ERRORS

fileOperationErrorStart:

jmp fileOperationErrorEnd ; SKIP ON START OF PROGRAM

13
fileOperationErrorOpen:

mov dx, offset outputErrorO

mov ah, 09h

int 21h

jmp exit ; CLOSE THE PROGRAM IF ERROR

fileOperationErrorRead:

mov dx, offset outputErrorR

mov ah, 09h

int 21h

jmp exit ; CLOSE THE PROGRAM IF ERROR

fileOperationErrorClose:

mov dx, offset outputErrorC

mov ah, 09h

int 21h

jmp exit ; CLOSE THE PROGRAM IF ERROR

fileOperationErrorEnd:

mov ah, 3dh ; OPEN EXISTING FILE

mov al, 0 ; FILE OPEN MODE

mov dx, offset inputFile ; FILENAME OF FILE

int 21h ; INTERRUPT

jc fileOperationErrorOpen ; PROCESS THE ERROR

mov inputHandle, ax ; IF NO ERROR, GET FILE


HANDLE

mov ah, 3Fh ; READ FILE

mov bx, inputHandle ; CHOOSE FILE HANDLE

mov cx, bufferSize ; HOW BIG CAN THE PROGRAM


HANDLE?

14
mov dx, offset buffer ; POINTER TO BUFFER VARIABLE

int 21h ; INTERRUPT

jc fileOperationErrorRead ; PROCESS THE ERROR

mov bytesRead, ax ; IF NO ERROR, GET FILE HANDLE

mov ah, 3Eh ; CLOSE FILE

mov bx, inputHandle ; CHOOSE FILE HANDLE TO CLOSE

int 21h ; INTERRUPT

jc fileOperationErrorClose ; PROCESS THE ERROR

cmp bytesRead, 0 ; CHECK TOTAL BYTES READ FROM


FILE

jnz bytesReadNotZero ; END PROGRAM IF ZERO BYTE READ

jmp Outputs

bytesReadNotZero:

; SENTENCE COUNTER

mov bx, 0 ; SET BX TO 0

; USE FOR CHARACTER POSITION

countSentencesLoop:

cmp bx, bytesRead ; CHECK CURRENT POSITION

je countSentencesEOS ; EQUAL BYTES FOUND

; REPRESENTS END OF STRING

; LOOP IS STOPPED

cmp buffer[bx], 2Eh ; COMPARE CURRENT CHARACTER

je incrementCountSentences ; FOR A DOT CHARACTER

; IF YET, THEN END OF SENTENCE

; COUNTSENTENCES INCREASE BY1

cmp buffer[bx], 21h ; COMPARE CURRENT CHARACTER

je incrementCountSentences ; FOR A EXCLAMATION MARK

15
cmp buffer[bx], 3Fh ; COMPARE CURRENT CHARACTER

je incrementCountSentences ; FOR QUESTION MARK


jmp incrementCountSentencesBX

incrementCountSentences:

inc countSentences ; INCREASE SENTENCE COUNTER

jmp incrementCountSentencesBX

incrementCountSentencesBX:

inc bx ; MOVE TO NEXT CHARACTER

jmp countSentencesLoop ; LOOP countSentencesLoop UNTIL END

countSentencesEOS:

mov bx, 0 ; CLEANUP BX = 0

; PARAGRAPH COUNTER

mov bx, 0 ; BX SET TO 0

; USE THIS FOR CHARACTER POSITION

countParagraphsLoop:

cmp bx, bytesRead ; CHECK IF CURRENT POSITION

jge countParagraphsEOS2 ; EQUALS BYTE FOUND

; REPRESENTS END OF STRING

; LOOP IS STOPPED

cmp buffer[bx], 0Dh ; COMPARE CURRENT CHARACTER

je incrementCountParagraphs ; FOR A CARRIAGE RETURN

jmp incrementCountParagraphsBX

incrementCountParagraphs:

inc countParagraph ; INCREASE PARAGRAPH COUNTER

jmp skipCRLFAndSpaceLoop

16
incrementCountParagraphsBX:

inc bx ; MOVE TO NEXT CHARACTER

jmp countParagraphsLoop ; LOOP UNTL END OF STRING

skipCRLFAndSpaceLoop:

cmp bx, bytesRead ; CHECK IF CURRENT POSITION

jge countParagraphsEOS ; EQUAL BYTES REPRESENTS END OF


STR

; LOOP IS STOPPED

cmp buffer[bx], 0Dh ; COMPARE FOR 'CR'

je skipCRLFAndSpaceLoopAddBX ; JUMP IF EQUAL

cmp buffer[bx], 0Ah ; COMPARE FOR 'LF'

je skipCRLFAndSpaceLoopAddBX ; JUMP IF EQUAL

cmp buffer[bx], 20h ; COMPARE FOR 'SP'

je skipCRLFAndSpaceLoopAddBX ; JUMP IF EQUAL

jmp incrementCountParagraphsBX ; IF CRLF NO LONGER FOUND

; JUMP TO incrementCountParagraphsBX

skipCRLFAndSpaceLoopAddBX:

inc bx ; MOVE OF ON TO NEXT CHARACTER

jmp skipCRLFAndSpaceLoop ; SKIP CR LF SP

; JUMP TO skipCRLFAndSpaceLoop

; TO RECHECK FOR CR LF SP

countParagraphsEOS2:

inc countParagraph

countParagraphsEOS:

mov bx, 0

Outputs:

; OUTPUT OF outputFileName

mov dx, offset outputFileName ; CHOOSE STRING TO PRINT

mov ah, 09h ; PRINT STRING

17
int 21h ; INTERRUPT

; OUTPUT OF inputFile

mov dx, offset inputFile ; CHOOSE STRING TO PRINT

mov ah, 09h ; PRINT STRING

int 21h

; OUTPUT outputSentences STRING

mov dx, offset outputSentences ; CHOOSE STRING TO PRINT

mov ah, 09h ; PRINT STRING

int 21h

; OUTPUT countSentences

mov ax, countSentences ; NUMBER TO PRINT

call printNumbers ; CALL printNumbers PROCEDURE

; OUTPUT outputParagraph STRING

mov dx, offset outputParagraph ; CHOOSE STRING TO PRINT

mov ah, 09h ; PRINT STRING

int 21h

; OUTPUT countParagraph

mov ax, countParagraph ; CHOOSE STRING TO PRINT

call printNumbers ; CALL printNumbers PROCEDURE

; END PROCESS

mov ah, 4ch

int 21h

printNumbers PROC

push bx

push cx

push dx

mov cx, 0 ; SET COUNTER TO 0

mov bx, 10d ; SET BX TO 10 TO BE DIVIDED WITH

pushToStackLoop:

mov dx, 0 ; DX = 0

18
div bx ; DIVIDE BX WITH AX

push dx ; REMAINDER STORE IN DX, PUSH DX

inc cx ; INCREASE STACK COUNTER

cmp ax, 0 ; COMPARE FOR 0

jnz pushToStackLoop ; IF NOT, LOOP FUNCTION

mov ah, 02h ; WRITE CHARACTER

printStackLoop:

pop dx ; POP LAST STACK VALUE TO DX

add dx, 30h ; 30h IS ASCII FOR '0'

int 21h

dec cx ; DECREASE STACK COUNTER

cmp cx, 0

jnz printStackLoop ; IF NOT ZERO, POP AND PRINT NEXT


VALUE

; FROM THE STACK AGAIN

pop dx

pop cx

pop bx

; RETURN TO PROC CALLER

ret

printNumbers ENDP

exit:

.exit

end start

19
ANALYSIS
RESULT OF PROGRAM

To execute the program, insert the name of the exe file. In the example that shown in
figure 1, pns was key in to the ms-dos. After pressing enter, the program was executed and
the result shows that in a bom.txt file, there are 3 sentences and 1 paragraphp found.

Figure 1 - Result of program

The program successfully determined the numbers of sentences and paragraphs as


required. Yet, it only can read the file name that written in the program. A partial program
of this task is shown in figure 2. In this program, the name of the file (bom.txt) that
required to be opened is assigned to inputFile. Therefore, once the program is executed , it
will this file and open it. Meanwhile, figure 2 also shows that there were 2 types of printed
messages that will be shown in this program, the error message and the output message.

The error message is the message that will displayed if any error occurs. There are
three types of error message designed in this program specifically to indicated the error of
Ms-dos filling. The program will shows the message of outputErrorO when the file wasn‟t
able to open, outputErrorR when the file wasn‟t able to be read and outputErrorC when the
file wasn‟t able to be closed. Meanwhile, output message from outputFileName,
outputParagraph and outputSentences will be shown in the resut in Ms-Dos.

20
Figure 2 - variable in data segment

On the other hand, „$‟ sign is a sign that used to show the desirable output of the
program. Thus, the name of the file will be displayed on the reading file while the numbers
of sentences and the numbers of paragraphs will be displayed in the rest of the two
messages.

in order to begin the counting sequence from zero, 0 is assigned to the variable
countParagraph and countSentences as the initial value of the counter. These two counter
will be used in counting the number of paragraph and sentences and shall be explain in the
next sentence and paragraph counting section.

MS-DOS FILING PROGRAM.

To carry out the open and import data from txt file, ms-dos filling method is required
to be used. This method consists of three major section: open file/create file, read file and
close file.

Figure 3 - Dos open file

716Ch is a dual function command which can be used to create a file or to open a
file. In this program, this command is used to open a file. The name of the file is assigned to

21
the source index so that the whole opening task will open according to the name that set in
the inputFile variable. If error was found during the loading of the file name, the program
will soon proceed to fileOperationErrorOpenwhich is a print message that will show the
message of “Unable to open file”. Figure 4 shows the message printing program for
fileOperationErrorOpen.

Figure 4 – fileOperationErrorOpen message printing program

Meanwhile to read a file, dos function 3FH is required. In this program, the input
handle will define which file to read while the bufferSize will define the reading size. On the
other side, the offset buffer is the pointer to the buffer variable. The program will jump to
fileOperationErrorRead if error occurs during the reading progress. Figure 6 illustrate the
error reading message displaying program. In this program, the message that assign to
variable outputErrorR will be displayed when error occurs during file reading.

Figure 5 - dos read file

Figure 6 - fileOperationErrorRead message printing program

Finally, the last ms-dos filling program will most certainly end with a file closing program. As
been shown in figure 7, Dos function 3Eh was used in the program as a file closing
command. TheinputHandle command will chose the file to be handled in this program. If

22
error occurs, the sequence will straight away move to fileOperationErrorClose as shown in
figure 8.

Figure 7 – dos close file

The operation of the fileOperationErrorCloseis almost similar with fileOperationErrorReadand


fileOperationErrorOpen which intend to print out the error message of closing file.

Figure 8 - fileOperationErrorClose message printing program

23
SENTENCE COUNTING

Before counting the numbers of sentence in a text file, bx register is set to 0. It is


use for character position. After that, program proceeded with by entering the sub program
name countSentencesLoop. in this section, the data from buffer[bx] will be compared with
dot character, exclaimation mark and question mark. If either one of them are equal, the
prgram will jump to incrementCountSentences and increase the countSentences variable
that set in the data segment. After increasing the countSentences, it will jump to
incrementCountSentencesBx to increase the bx value. Once the bx value is increased, it will
again loop back to countSentencesLoop to compare the next character. The looping
program is shown in figure 8.

Figure 9 - Count Sentences

In contrast, if the non-of the comparison are equal, the program will loop to the
incrementCountsentcesBx to increase the value of bx and then loop back again to
countSentenceLoop. In this case, the value of the counSentences will not be increased and
no sentence count during this move.

24
PARAGRAPH COUNTING

In the paragraph counting section, the program start with comparing bx with
bytesRead. After the comparison, itwill straight away jump to counterParagraphsEOS2 and
increase the countParagraph if the value of bytesRead is equal to zero. If the value of
bytesRead is not equals to zero, it will proceed the comparison with CR or LF.

Again during this comparison section, if any of it is matched, the program will jump
to incrementCountParagraphs and increase countParagraph. Yet, after increasing the
counterParagraph, instead of jumping back to the beginning of paragraph counting
program. In fact, it jump to skipCRLFAndSpaceLoop to recheck again whether there is still
any CR, LF or space occur after detecting the similarity in IncrementCountParagraphs.

This rechecking progress will helps on eliminating the posibility of having blank space
in new line and also larger spacing. It will skip all the following CR,LF and space until it
detect a character and jump back again to incrementCountParagraphsBx to increase the
paragraphs counter. Figure 9 at below shows the program for counting a paragraphs.

Figure 10 - Count paragraph.

After gone through this paragraph counting program the total number of paragraph will be
stored in countParagraph and be ready to be display in the output of the program.

25
CONCLUSION
The program is successfully design. And the number of the sentence and paragraph were able to be
calculated. Although there are some limitations in this program, still the program can be further
improved in the future.

REFERENCE
1. 80386/80486 Registers, Retrieved on December 19 2012, from : www.tu-
ilmenau.de/fileadmin/media/ra/template/.../webster_teil.pdf
2. Intel 80386 Programmer's Reference Manual,1986, Retrieved on December 19 2012,
from : pdos.csail.mit.edu/6.828/2012/readings/i386.pdf
3. Ismail Saad, 2010, Introduction to computer, KM40203 Mikropemproses Dan
Elektronik lecture note.

26
Contents
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING ....................................................... 1
FUNDAMENTAL STUDY ........................................................................................................................ 2
1. .Model Small .............................................................................................................................. 3
PROBLEM STATEMENT............................................................................................................................ 6
PROGRAM OBJECTIVES ........................................................................................................................... 6
DESIGN STAGE......................................................................................................................................... 6
ANALYSIS ............................................................................................................................................... 20
CONCLUSION......................................................................................................................................... 26
REFERENCE ............................................................................................................................................ 26

27

You might also like