MIC Chap 2 Notes
MIC Chap 2 Notes
Subroutine
4. Initialization checklist
Initialization task is to make the checklist of entire variables, constants, all the registers, flags
and programmable ports
5. Choosing instructions
We should choose those instructions that make program smaller in size and more importantly
efficient in execution.
6. Converting algorithms to assembly language program
Every step in the algorithm is converted into program statement using correct and efficient
instructions or group of instructions.
What are the major steps in developing ALP?
1) The first step in the process is to develop assembly program text. Assemblers typically provide
assembly text editors to help program development. At assemble time, the input text is passed to
the assembler, which parses the text, emitting a program listing and possibly error reports.
2) If there are no errors, the assembler produces a binary machine language module. The module
must contain information about where the program or module is to be loaded in memory, and if it
contains the starting address of the program, this start symbol must be made known.
3) If the module has to be linked with other modules, then it must include this additional linkage
information. This means that all labels in the module that have to be visible to other modules
must be specified as public symbols. Similarly, all labels that are defined in other modules must
be specified as external symbols.
4) At link time, the linker combines separately assembled modules into a single load module. The
linker will also add any initialization or finalization code to allow the operating system to start
the program or return control to the OS, once the program has completed.
5) At load time, the program loader copies the program into computer’s main memory.
2) Assembler
An assembler is a program used to translate or convert the assembly language mnemonics
of source code program for instructions to the corresponding binary codes(machine language)
which is called as object code or machine code of the program.
It uses source file with .ASM extension as input.
Ex TASM (Borland’s Turbo Assembler), MASM (Microsoft Macro Assembler) etc.
3) LINKER:
A linker is a program used to join together several objects files into one large object file. When writing
large programs, it is usually much more efficient to divide the large program into smaller modules. Each
module can be individually written, tested and debugged. When all the module work, they can be linked
together to form a large functioning program.
The linker produces a link file which contains the binary codes for all the combined modules. The
linker also produces a link map which contains the address information to the program, it only
assigns relative addresses starting from zero. This form of the program is said to be relocatable,
because it can be put anywhere in memory to be run.
The command on command prompt for converting .obj file to ,EXE file is as given below:
C : \ MASM \ BIN \ > LINK myprog.obj;
C : \ TASM \ > TLINK myprog.obj;
DEBUGGER:
A debugger is a program which allows us to load object code program into system memory execute
the program, and debug it.
How does a debugger help in debugging a program?
1. The debugger allows us to look at the contents of registers and memory locations after our
program runs.
2. It allows us to change the contents of register and memory location and return the program.
3. Some debugger allows us to stop execution after each instruction so we can check or alter
memory and register
4. A debugger also allows us to set a breakdown at any point in our program. When we run a
program, the system will execute instructions up to this breakpoint and stop. We can then examine
register and memory contents to see if the result are correct at that point. If the result are correct, we
can move the break point to a later point in our program. If result are not correct we can check the
program up to that point to find out why are not correct.
Ex: DOS Debug command,Borlands turbo debugger TD.
ii) Linker
1. It is a programming tool used to convert Object code into executable program.
2. It combines ,if requested ,more than one separated assembled modules into one executable
module such as two or more assembly programs or an assembly language with C program.
3. It generates .EXE module
(iii) Editor
1. It is a program which helps to construct assembly language program with a file extension
.asm, in right format so that the assembler will translate it to machine language.
2. It enables one to create, edit, save, copy and make modification in source file.
Assembler Directive
5) DT :Define Ten byte .This directive is used to tell the assembler to define a variable which is 10 bytes in
length or to reserve 10 bytes of storage in memory.
NUM DT ? ; Allocate Ten memory locations;
ARRAY DT 1 ,2 ,3, 4, 9 ; Allocate fifty memory locations
List DB 10 DUP(0) ; Allocate 100 memory locations.
Structure declaration does not allocate memory , but storage space is allocated when structure variable is
defined.
Variable Structure_name <initialization>
E.g E1.EMPLOYEE <01,’Martin’,28>
Structure variable can be accessed by using dot operator
Varablename.fieldname
e.g. MOV AX,E1.EMP_NUM
7)EQU :Equate to
The EQU directive is used to declare the micro symbols to which some constant value is assigned. Micro
assembler will replace every occurrence of the symbol in a program by its value.
Syntax: Symbol_name EQU expression
• e.g NUM EQU 50
10) EVEN: - The directive even is used to tell the assembler to increment the location counter to
the next even memory address.
If the location counter is already pointing to an even address it should not be incremented. The 8086
reads/writes data in one machine cycle, if data is to be accessed from even location. It requires two
bus cycles to access a word from an odd memory location. This directive can be used in both Code
and Data segments.
Example: - DATA SEGMENT
Array DB 9 DUP (?)
Even
Block DW 100H DUP (0)
DATA ENDS
11) LABEL : The LABEL directive is used to give a name to the current value in the
location counter .IT enables you to redefine the attributes of a data variable or instruction
label.
Syntax: variable_name LABEL type_specifier
e.g STACK_TOP LABEL WORD
TEMP LABEL BYTE
12) DUP : Duplicate memory location
This directive can be used to generate multiple bytes or words with known as well as un-
initialized values.
e.g TABLE DW 100 DUP(0) ; Create array of 100 words all contains data 0
Array DB 9 DUP (?) ; Create array of 9 bytes with unknown value.
2) SEGMENT :Used to indicate the beginning of logical segment . Preceding the SEGMENT directive is the
name you want to give the segment
Syntax:
Segment_Name SEGMENT [Word/Public]
WORD indicates that the segment has to be located at the next available address; otherwise the segment will be
located at the next available paragraph which might waste upto 15 bytes of the memory.
Type specifier PUBLIC indicates that this segment may be put together with other segments named CODE from
other assembly modules when modules are linked together.
e.g My_data SEGMENT
My_data ENDS
3) ENDS : End of segment .The directive ENDS is used with the name of a segment to indicate the end
of that logical segment (which contains instructions or data).
CODE SEGMENT ;Start of logical segment
------ ;Instruction statements
CODE ENDS ;End of segment named CODE.
5) Dot . directives
.Directives are set of directives used by memory models such as Tiny and Small models making assembly
language structures simpler. They define current memory model in use, type of CPU in use.
Different .Directives are
a).MODEL Directive :
syntax: .MODEL <Memory_model_type>
ex: .Model Small
● Tiny- Single segment, create .COM executable code which is machine independent.
● Small- Single Code Segment and Single Data Segment.
● Medium- Multiple Code segment and Single Data Segment.
● Compact –Single Code segment and Multiple Data Segment.
● Large - Multiple code as well as Multiple Data Segment (segments within 64K size)
● Huge – Multiple copies as well as Multiple data segments.(no 64K size
limit) All model except tiny creates .EXE code which is OS dependent.
Example : MOV AX, SIZE Total ; Find no of bytes in Total and load length to CX.
c) OFFSET: This directive tells the assembler to determine the offset or displacement of a named data item
or procedure from the start of segment which contains it. Used to load the offset of variable into a register
sothat variable can be accessed with one of the indexed addressing mode.
Syntax : OFFSET Variable_name
Ex OFFSET BX,PRICES ;determine the offset of variable and PRICES from seg start and load
displacement in BX
d) SEG :Segment
Used to determine the segment in which the specified data item is defined.
Syntax: SEG Variable_name
1)Public : This directive is used to tell the assembler that a specified name or label will be accessed
from other modules. It helps in managing the multiple program modules by sharing the global
variable or procedures.
Ex . PUBLIC ABC,XYZ makes two variables available to other assembly modules.
2)EXTERN :External
This directive is used to tell the assembler that the names or labels following the directive are
in some other assembly module.
Syntax for variable reference
EXTERN Varaiable_name1:reference_type,…… variable_nameN:reference _type
For procedure reference
EXTERN procedure_name:[NEAR/FAR]
Ex: EXTERN msg:byte,name:word
EXTERN Display:FAR
3)PTR
Uses to indicate type of memory access i.e BYTE/WORD/DWORD
If instruction INC[SI] is given , we will not be able to decide whether to code for byte
increment or word increment.so PTR is used as
INC BYTE PTR[SI]
ADD AL, WORD PTR[SI]