map notes_ chapter 4
TRANSCRIPT
8/19/2019 MAP Notes_ Chapter 4
http://slidepdf.com/reader/full/map-notes-chapter-4 1/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.
8/19/2019 MAP Notes_ Chapter 4
http://slidepdf.com/reader/full/map-notes-chapter-4 2/5
• Converting algorithms to assembly language programs:
nce 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 e!ecution.
"irst we declare the data in the data segment, then we write the actual program in the code segment.
Assembly language program development tools:
• Editor:
• #t is used to type the assembly language statements for the program and save in a file.
• The file containing the te!t of assembly language statements is called as source file and
has the e!tension .asm
•
• Assembler:
• $ssembler is a software which reads the te!t from the source file, translates into
respective binary codes and saves into two files, one with the e!tension .obj called as
object file and one with the e!tension .lst called as list file.
• The ob%ect file contains binary codes and addresses of the instructions.
• The list file contains assembly language statements, binary codes, and offset address for
each instruction.
•
$ssembler indicates synta! errors if any in the source file.•
• inker:
• &arge 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 e!ecutable program.
The linker is used to %oin many ob%ect files into a single large ob%ect file.
• 'sually linker produces files with the e!tension .e!e which can be directly loaded in the
memory and e!ecuted.
•
• Debugger:
#t enables the program to be loaded into the system memory, e!ecute it and then debug it.
#t also enables to insert breakpoints at any desired locations, change the content of
register, memory location and rerun the program.
8/19/2019 MAP Notes_ Chapter 4
http://slidepdf.com/reader/full/map-notes-chapter-4 3/5
Assembler directives
$ssembly language contains two types of statements
•( #nstructions
• ( )irectives
#nstructions are translated into machine code by the assembler which the processor understands
by decoding them. #n other words instructions, instruct the processor to do a particular task.
)irectives are instructions to the assembler which help the assembler in the assembly process
and these directives are not translated into machine code.
r
*tatements that direct the assembler to do some special task
• D!: define byte
The )+ directive is used to reserve a byte or bytes of memory location in the available memory.
Eg array )+ -h /assembler reserves 0 byte of memory for the variable named sum and
initializes its value to -1
• D": define word
The )W directive is used to reserve a word or words of memory location in the available
memory.
Eg value )W 0-23h /this makes the assembler reserve a word in memory1
• D#:define #uad word
This directive is used to direct the assembler to reserve four words 45 bytes6 of memory for the
specified variable.
Eg value )7 0-2389:50-2389:5h /this makes the assembler reserve 3 words in memory1
• DD: define double word
This directive is used to direct the assembler to reserve two words 43 bytes6 of memory for the
specified variable.
Eg value )) 0-2389:5h /this makes the assembler reserve - words in memory1
• D$: define ten bytes
This directive directs the assembler to define the specified variable requiring 0 bytes for its
storage and initialize 0 bytes with the specified values.
Eg value )T 0-2389:50-2389:50-h /this makes the assembler reserve ten bytes in memory1
8/19/2019 MAP Notes_ Chapter 4
http://slidepdf.com/reader/full/map-notes-chapter-4 4/5
•
• A%%&'E: assume logical segment name
The $**';E 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 $**';E <* <)E directs the assembler that the machine code4e!ecutable
program6 are available in a segment named <)E and hence <* register is to be loaded with the
segment address for the label <)E, while loading.
Eg the statement $**';E )* )$T$ indicates to the assembler that the data items related to
the program are available in the logical segment named )$T$, and )* register is to be
initialized by the segment address for data segment while loading
• %E('E)$:
The segment directive is used to indicate the start of a logical segment.
Eg <)E *E=;E>T statement indicates to the assembler the start of a logical segment called <)E
Eg )$T$ *E=;E>T statement indicates to the assembler the start of a logical segment called )$T$
• E)D%: end of segment
This directive marks the end of a logical segment. The logical segments are assigned with the names
using $**';E directive. The names appear with the E>)* directive as prefi! to mark the end of those
particular segments.
Eg )$T$ *E=;E>T
.
.
)$T$ E>)*
• E)D: end of program
The E>) directive marks the end of an assembly language program. When the assembler comes across
the E>) directive, it ignores the source lines available later on.
• *rg +originate, directive
This assembler directive is used to assign starting memory location of program.
#f org is not given then program code will be stored from the effective address h by default.
Eg rg 0h will start storing the program from the address 0h.
• E#& +e-uate, 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. *o when we want
to change the value. We need to go everywhere in the program where we entered the value.
8/19/2019 MAP Notes_ Chapter 4
http://slidepdf.com/reader/full/map-notes-chapter-4 5/5
#nstead 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
<ount equ 0h
>ow the above directive will assign value 0h to count label.
>ow we use this count label many times in the main program. #f we want to change its value, we will %ust
change the value above once and not go to every instruction like others.
• .roc 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. $dd proc far?near
The above statement identifies the start of a procedure named add and tells the assembler that the
procedure is far 4different code segment6
• 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 ne!t even
address if it is not already at the even address.
$s we know that mp 559 is a 09 bit processor, therefore it can access a word in one machine cycle.
+ut the condition is that the word is located at an even address.
Eg08h is a word located at -h and -0h
Which means that at
-h @ 0h
-0h @ 8h
Aence in such case we donBt require an even directive.
+ut if the word is located at -0h and --h
Then it means that
-0h @ 0h
--h @ 8h
>ow to access this word it will take - machine cycles, hence to reduce the access time we use even
directive