Anda di halaman 1dari 5

MAP notes

Chapter 4: The Art of Assembly language programming


Program development steps:

Defining the problem:

The first step in writing program is to think very carefully about the problem that you want the program to
solve.

Algorithm:

The sequence which your program should follow can be specified as a series of steps or in other words
sequence of operation.

Flowchart:

The flowchart is a graphical representation of the program operation or task. Each specific operation is
specified by different symbols.

Initialization checklist:

There may be many variables and segment registers which need to be defined in the program, but before
defining they need to be initialized.
The best way to approach the initialization task is to make the checklist of entire variables and registers
which are going to be used in the program.

Choosing instructions:

Proper instructions which are required in the program are chosen. Which means that entire instruction set
must be known.

Converting algorithms to assembly language programs:

Once you have selected the instructions for the operations to be performed then arrange these instructions
in sequence as per algorithm so that desired output must be obtained after execution.
First we declare the data in the data segment, then we write the actual program in the code segment.

Assembly language program development tools:

Editor:

It is used to type the assembly language statements for the program and save in a file.

The file containing the text of assembly language statements is called as source file and
has the extension .asm

Assembler:

Assembler is a software which reads the text from the source file, translates into
respective binary codes and saves into two files, one with the extension .obj called as
object file and one with the extension .lst called as list file.

The object file contains binary codes and addresses of the instructions.

The list file contains assembly language statements, binary codes, and offset address for
each instruction.

Assembler indicates syntax errors if any in the source file.

Linker:

Large assembly language programs are usually divided into many small modules.

The code for each module are separately developed, tested and finally linked into a single
large executable program.
The linker is used to join many object files into a single large object file.

Usually linker produces files with the extension .exe which can be directly loaded in the
memory and executed.

Debugger:
It enables the program to be loaded into the system memory, execute it and then debug it.
It also enables to insert breakpoints at any desired locations, change the content of
register, memory location and rerun the program.

Assembler directives
Assembly language contains two types of statements

- Instructions

- Directives

Instructions are translated into machine code by the assembler which the processor understands
by decoding them. In other words instructions, instruct the processor to do a particular task.
Directives are instructions to the assembler which help the assembler in the assembly process
and these directives are not translated into machine code.
Or
Statements that direct the assembler to do some special task

DB: define byte

The DB directive is used to reserve a byte or bytes of memory location in the available memory.
Eg: array DB 20h {assembler reserves 1 byte of memory for the variable named sum and
initializes its value to 20}

DW: define word

The DW directive is used to reserve a word or words of memory location in the available
memory.
Eg: value DW 1234h {this makes the assembler reserve a word in memory}

DQ:define Quad word

This directive is used to direct the assembler to reserve four words (8 bytes) of memory for the
specified variable.
Eg: value DQ 1234567812345678h {this makes the assembler reserve 4 words in memory}

DD: define double word

This directive is used to direct the assembler to reserve two words (4 bytes) of memory for the
specified variable.
Eg: value DD 12345678h {this makes the assembler reserve 2 words in memory}

DT: define ten bytes

This directive directs the assembler to define the specified variable requiring 10 bytes for its
storage and initialize 10 bytes with the specified values.
Eg: value DT 123456781234567812h {this makes the assembler reserve ten bytes in memory}

ASSUME: assume logical segment name

The ASSUME directive is used to inform the assembler the names of the logical segments to be
assumed for different segments used in the program.
Eg: the statement ASSUME CS : CODE directs the assembler that the machine code(executable
program) are available in a segment named CODE and hence CS register is to be loaded with the
segment address for the label CODE, while loading.
Eg: the statement ASSUME DS : DATA indicates to the assembler that the data items related to
the program are available in the logical segment named DATA, and DS register is to be
initialized by the segment address for data segment while loading

SEGMENT:

The segment directive is used to indicate the start of a logical segment.


Eg: CODE SEGMENT statement indicates to the assembler the start of a logical segment called CODE
Eg: DATA SEGMENT statement indicates to the assembler the start of a logical segment called DATA

ENDS: end of segment

This directive marks the end of a logical segment. The logical segments are assigned with the names
using ASSUME directive. The names appear with the ENDS directive as prefix to mark the end of those
particular segments.
Eg: DATA SEGMENT
.
.
DATA ENDS

END: end of program

The END directive marks the end of an assembly language program. When the assembler comes across
the END directive, it ignores the source lines available later on.

Org (originate) directive

This assembler directive is used to assign starting memory location of program.


If org is not given then program code will be stored from the effective address 0000h by default.
Eg: Org 1000h will start storing the program from the address 1000h.

EQU (equate) directive

This directive tells the assembler to assign a value to the corresponding label.
This directive is used in general when we use some value ,multiple times in a program. So when we want
to change the value. We need to go everywhere in the program where we entered the value.

Instead of that what we will do is that we will use equ directive and assign that value to a label through
this directive as follows:
Count equ 100h
Now the above directive will assign value 100h to count label.
Now we use this count label many times in the main program. If we want to change its value, we will just
change the value above once and not go to every instruction like others.

Proc and endp directive

The subprogram called as subroutine is also called as procedure.


The proc and endp directive are used to indicate the start and of the subprogram or procedure.
Eg. Add proc far/near
The above statement identifies the start of a procedure named add and tells the assembler that the
procedure is far (different code segment)

Endp

The above directive indicates the end of procedure.

Even directive

This assembler directive informs the assembler to increment the memory location counter to the next even
address if it is not already at the even address.
As we know that mp 8086 is a 16 bit processor, therefore it can access a word in one machine cycle.
But the condition is that the word is located at an even address.
Eg:1005h is a word located at 2000h and 2001h
Which means that at:
2000h 10h
2001h 05h
Hence in such case we dont require an even directive.
But if the word is located at 2001h and 2002h
Then it means that:
2001h 10h
2002h 05h
Now to access this word it will take 2 machine cycles, hence to reduce the access time we use even
directive

Anda mungkin juga menyukai