An assembly language is a type of low-level programming language that is intended to communicate directly with a computer's hardware. Unlike machine language, which consists of binary and hexadecimal characters, assembly languages are designed to be readable by humans.
2. Program Development Step
🞇 List the program development steps for
assembly language programming:-
1. Defining the problem
2. Algorithm
3. Flowchart
4. Initialization checklist
5. Choosing instructions
6.Converting algorithms to assembly language program
3. 1. Defining the problem
The first step in writing program is to think very
carefully about the problem that you want to solve.
At this point you need to write down program
but you must know what you would like to do.
4. 2. Algorithm
The formula or sequence of operation or tasks need
to perform by your program.
Can be specified as a step in general English and
is often called as algorithm.
5. 3. Flowchart
The flowchart is a graphically representation of
the program operation or task.
Connector
Process
Decision
Input
/Output
Subroutine
Termination
6. 4. Initialization checklist
In program there are many Variables, Constants and
various Segment Registers, Flags, Stack,
Programmable ports etc. which must be initialize
properly.
The best way to initialization of task is to make
the checklist of the entire Variables, Constants and
various Segment Registers, Flags, Stack,
Programmable ports etc.
7. 5. Choosing instructions
your
Choose proper instruction that performs
problems or task.
This is an important step, so you must know
entire instruction set of the Microprocessor.
8. 6. Converting algorithms to
assembly language program
Select the instruction for the operation to be
performed.
In assembly language program, a first step is to
set up and declare the data structure.
Then write down the instruction required for
initialization at the start of the code screen.
Next determine the instructions required to
implement the major action in the algorithm.
10. 1.Editor
An editor is a program which helps to construct
ALP in right format so that the assembler will
translate it correctly to machine language.
So type program using Editor.
This form of program is called as source
program.
11. 2.Assembler
Assembler is a program that translates assembly
language program to the correct binary code.
It also generates the file called as object file with
extension .obj.
It also displays syntax errors in the program, if any.
Example ofAssembler are MASM (Microsoft Macro
Assembler.
12. 3.Linker
It is a programming tool used to convert Object
code into executable program called .EXE module.
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.
13. 4.Debugger
Debugger is a program that allows the execution
of program in single step mode under the control
of the user.
The errors in program can be located and corrected
using a debugger.
Debugger generates .exe file.
14. Program Development Process
1. Source file creation
2. Object code generation
3. Executable file creation
4. Program Running
5. Program Testing
6. Program Debugging
15. 1 Source file creation:-
The source file is created and edited using
text editor and must have extension .ASM.
2 Object code generation:-
The assembler is used to translate assembly
language source code to re-locatable object
code.
16. 3 Executable file creation:-
Linker is used to create an executable file.
4 Program Running:-
The executable file can be run by entering the
name of executable file on the prompt and by
passing ENTER key on the keyboard.
17. 5 Program Testing:-
The result or output generated by the program has
to be tested for their validity.
If any error occurs in the result, then program
should be debug.
6 Program Debugging:-
The errors in the program can be located using
debugger.
The executable file of the program to be
debugged must be created with the program
debug option.
18. Assembler Directives and
Operator
Assembly language program supports a number of
reserve word i.e. key words that enable control of
program assembler and lists.
These words are called as aAssembler Directives,
acts only during the assembly of the program.
So, directives are the statement that gives direction
to the assembler.
Directives are divided into various categories.
19. Data Definition Directives
DB : Define Bytes
DW : Define Words
DD : Define Double Word
DQ : Define Quad Word
DT : Define Ten Byte
STRUCT : Structure Declaration
RECORD
EQU : Equate to
ORG : Originate
ALIGN : Alignment of memory addresses.
EVEN : Align as even memory location
LABEL
20. DB:Define Bytes
DB - Define byte (8 bits)
It is used to declare a byte type variable of 8 bit. It
also can be used to declare an array of bytes.
The range of values that can be stored in a byte is 0
to 255 for unsigned numbers and –128 to +128 for
signed numbers.
General form:-
🞇 Name_Of_Variable DB → Initialization _Value(,s)
21. DW:Define Words
The DW directive is used to define word type (16bit)
instead of bytes.
The range of values that can be stored in a word is 0
to 655535 for unsigned numbers and -32768 to
+32768 for signed numbers.
General form:-
🞇 Name _ Of_Variable DW→ Initialization _ Value(,s)
22. Define Double Word
The DD directive is used to define a double
word type i.e. 4byte (32 bits)type variable.
The range of the values that can be stored in a
double word is 0 to 232-1 for unsigned no. and
signed integer no is -232-1 to +232-1
General form:-
🞇 Name _ Of_Variable DD → Initialization _ Value(,s)
23. DQ( Define Quad Word)
This is used to define a quad word (64-bit)or 8
byte type variable.
The range of the values that can be stored in a
double word is 0 to 264-1 for unsigned no. and
signed integer no is -264-1 to +264-1
General form:-
🞇 Name _ Of_Variable DQ → Initialization _ Value(,s)
24. DT:Define Ten Byte
The DT Directive is used to define a ten byte
type variable.
It can be used to define single or multiple
10 byte variables.
The range of the values that can be stored is 0
to 280-1 for unsigned no. and signed integer no
is -280-1 to +280-1
General form:-
🞇 Name _ Of_Variable DT → Initialization _ Value(,s)
25. STRUCT: Structure Declaration
The directive STRUCT is used to declare the data
type which is a collection of primary data type
(DB,DW,DD).
The structure declaration allow the user to define a
variable which has more than one data type.
General form:-
26. STRUCT
Structure variable definition
The general form of a structure definition is as
follows:
🞇 Variable Structure _ Name<Initializations>
🞇 Example
🞇 EMPLOYEE STRUCT
🞇 EMP_N
🞇
DW ?
EMP_NAME DB 25DUP
🞇 EMP_AGE DB
🞇 EMP_DEPT DB ?
🞇 EMPLOYEE ENDS
27. RECORD
The directive RECORD is used to define a bit
pattern within a byte or a word.
It is similar to the bit-wise access in C
language.
The RECORD definition helps in encoding or
decoding of bit for which some meaning is
assigned.
29. EQU: Equate to
The EQU directive is used to declare the
symbols to which some constant value is
assigned.
Such symbols are called as macro symbols , so
macro assembler will replace every occurrences
of the symbol in a program by its value.
31. ORG: Originate
The directives ORG assigns the location
counter with the value specified in the directive.
General form
ORG [$+] Numeric_value
Examples
ORG 100H
ORG $
ORG $+100
32. ALIGN: Alignment of memory
addresses.
The directive ALIGN is used to force the
assembler to align the next data item or
instruction according to given value.
General form
Examples
ALIGN Numeric_Value
ALIGN 4 Align 4 means : align next data and
division by 4.
33. EVEN: Align as even memory
location
The directive EVEN is used to inform the assembler
to increment the location counter to the next even
memory address.
If it is location counter is already pointing to even
memory address, it should not be incremented.
The 8086 processor read a word from the memory
in one bus cycle while accessing an even memory
address word.
35. LABEL
The directive LABEL enables you to redefine
the attribute of a data variable or instruction
label.
General form
Variable_Name LABEL Type_Specifier
Examples
TEMP LABEL BYTE
NUMLABEL WORD
36. DUP:Duplicate memory
location
The DUP directive can be used to generate
multiple bytes or words with known as well as
un-initialized values.
Example General form : DUP?
Table dw
Stars db
ARRAY3
100DUP(0)
50 dup(’*’)
DB30 DUP(?)
37. Program Organization
Directive
ASSUME
SEGMENT
ENDS: END OF THE SEGMENT
END: END OF THE PROGRAM
CODE: Simplified CODE Segment directive
DATA: Simplified DA
TA Segment directive
STACK: Simplified Stack Segment directive
MODEL: Memory model declaration for
segments.
38. Program Organization
Directive :ASSUME
The directive ASSUME informs the
assembler the name of the logical segments
that should be used for a specified segment.
When program is loaded, the processor segment
register should point to the respective logical
segments.
39. ASSUME
General form:
ASSUME
Seg _ Reg: Seg _ Name
Where,ASSUME is a assembler directive.
Seg _ Reg is any of the segment register
i.e. CS,DS,SS,ES.
Seg _ Name is the name of an user defined segment.
Example
ASSUME CS:CODE,DS:DATA.
40. Program Organization
Directive : SEGMENT
The directive SEGMENT is used to indicate the
beginning of the logical segment.
The directive SEGMENT follows the name of
the segment.
41. SEGMENT
General form:
SEGMENT
SEGMENT _ Name SEGMENT
Example
DATASEGMENT ………
Program Data definition here
DATAENDS
CODE SEGMENT ………
Program Code definition here
CODE ENDS
42. Program Organization
Directive :ENDS
ENDS: END OFTHE SEGMENT
The directive ENDS informs the assembler the end
of the segment.
The directive ENDS and SEGMENT must
enclosed the segment data or code of the program.
43. ENDS
General form:
ENDS
SEGMENT _ Name ENDS
Example
DATASEGMENT ………
Program Data definition here
DATAENDS
CODE SEGMENT ………
Program Code definition here
CODE ENDS
44. Program Organization
Directive : END
END:END OFTHE PROGRAM
The directive END is used to inform assembler
the end of the program.
General form: END
END [Start_Address]
The optional start _ address specifies the
location in the code segment where execution is
to be start.
45. Program Organization
Directive : CODE
CODE: Simplified CODE Segment directive
This simplified segment directive defines the
code segment.
All executable code must be placed in this
segment.
General form: CODE
.CODE[NAME]
46. Program Organization
Directive : DATA
DATA: Simplified DATASegment directive
This simplified segment directive defines the data
segment for initialized near data.
All data define and declaration must be placed in
this segment.
General form: DATA
.DATA
47. Program Organization
Directive : STACK
STACK: Simplified Stack Segment directive
This simplified segment directive define the
stack segment
Default size of the stack is 1024 bytes.
General form: STACK
. STACK 100
48. Program Organization
Directive: MODEL
MODEL: Memory model declaration for segments.
This simplified segment directive creates default
segments.
General form: MODEL
.MODEL memory _ small
WHERE,
Memory model can be…
TINY: MASM 6.0, used for .COM program.
SMALL: all data in one segment and all code in one
segment.
50. Value Returning Attribute
Directive :LENGTH
The directive LENGTH informs the assembler
about the number of the elements in a data
items such as array.
If the array is defined with DB, then it returns
number of bytes allocated to a variable.
52. Value Returning Attribute
Directive :SIZE
The directive SIZE is same as Length except
that it returns number of bytes allocated to a
variable or data item instead of the number of
elements in it.
General form:-
SIZE Variable _ Name
EXAMPLE:-
MOV CX, SIZE NAME
53. Value Returning Attribute
Directive :OFFSET
The directive OFFSET informs the assembler to
determine the displacement of the specified
variable w.r.to the base of the segment.
It usually used to load a offset of a variable
into the register.
Using OFFSET value, a variable can be
referred indexed addressing mode.
55. Value Returning Attribute
Directive :SEG
The directive SEG is used to determine the
segment in which the specified data items
is defined.
General form:-
SEG Variable _ Name
EXAMPLE:-
MOV DS, SEG MSG
56. Value Returning Attribute
Directive :TYPE
The directive TYPE is used to determine the
type of the data items.
General form:-
TYPE Variable _ Name
EXAMPLE:-
ADD BX, TYPE NUM
58. Procedure Definition Directive
: PROC
PROC - The PROC directive is used to identify
the start of a procedure.
The term near or far is used to specify the type of
the procedure if the term is not specified , then
assembler assumes NEAR as a type Specifies.
General Form:
🞇 Procedure _ name PROC [NEAR/FAR]
60. Procedure Definition Directive
: ENDP
ENDP: END OF PROCEDURE
ENDP The directive is used along with the
name of the procedure to indicate the end of a
procedure to the assembler.
General Form : Procedure _ name ENDP
EXAMPLE: FACTORIAL ENDP
62. MACRO Definition Directive:-
MACRO
MACRO:
The directive MACRO informs the assembler
the beginning of a MACRO.
It consists of name of a MACRO followed by
keyword MACRO and MACROARGUMENT.
General Form :
MACRO_ NAME MACRO [ARGUMENT 1
….,…..ARGUMENT N]
63. MACRO
Example :-
DISPMACRO MSG … whose name is display by MACRO
PUSHAX
PUSH DX
MOVAH, 09H
LEADX ,MSG
INT 21H
POPDX
POPAX
ENDM
…… open subroutine
…… open subroutine
…… Read the string, 09h is function
to display string
…… Load effective address
……Termination of program with
a return code
…… Avoiding overhead of writing the
repeat pattern of the code.
…… End of MACRO
64. MACRO Definition Directive
:ENDM
ENDM: END OF MACRO
The directive ENDM informs the assembler
the end of the MACRO.
The directive MACRO and ENDM must
enclose the definition, declaration.
General Form :
ENDM
65. ENDM
Example :-
DISPMACRO MSG …whose name is display by MACRO
PUSHAX
PUSH DX
MOVAH, 09H
LEADX ,MSG
INT 21H
POPDX
POPAX
ENDM
…… open subroutine
…… open subroutine
…… Read the string, 09h is function
to display string
…… Load effective address
……Termination of program with
a return code
……Avoiding overhead of writing the
repeat pattern of the code.
…… End of MACRO
67. Data Control Directive :
PUBLIC
PUBLIC: the directive PUBLIC informs the
assembler that specified variable or segment can be
accessed from other program module.
It helps in managing the multiple program module
by sharing global variables.
General Form :
PUBLIC VARIABLE 1,……. VARIABLE N
69. Data Control Directive
: EXTRN
EXTRN: EXTERNAL
The directive EXTRN informs the assembler that
the data items or label following the directive will be
used in a program module.
General Form :
EXTRN VARIABLE_NAME1,…….
VARIABLE _NAME N
71. Data Control Directive : PTR
PTR: POINTER
The directive PTR is used to indicate the type of
the memory access i.e. BYTE/WORD/DWORD.
General Form :
PTR
EXAMPLE
INC BYTE PTR[DI]…..Increment byte pointer
73. Branch Displacement Directive
: SHORT
SHORT
One byte displacement is required to code to
jump instruction.
General Form :
JKPSHORT NEXT
74. Branch Displacement Directive
: LABEL
LABEL:
Assign a name to the current value in the
location counter.
General Form :
LABLE
EXAMPLE
LABLE_NAME
75. File Inclusion Directive
INCLUDE
This INCLUDE directive is used to insert a block
of source code from the named file into the current
source module.
The directive INCLUDE informs the assembler to
include the statement defined in the include file.
General Form :
INCLUDE<FILE PATH>
EXAMPLE
INCLUDEC:MASMMACRO.LI
B
76. Describe model of assembly
language programming
Note :Any one model can be considered.
Model 1 :
1) Using SEGMENT,ASSUME and ENDS directives
2) In this Data _ Seg is the name of the data segment where
data are declared.
3) Code _ Seg is the name of the code segment where code
is written.
4) Start is the label name used to initialize the CSregister.
5) ENDS to indicate the ends of code and data segment
6) END marks the end of the program.
77.
78. Model 2 :
a. Using .Data and .code directive
b. In this, .model small is used to indicate small
memory model is used in the program
c. Stack 100 to indicate 100 word memory locations
reserved for stack
d. Data indicates start of the data segment where
data declaration of the program is made.
e. Code indicates the beginning of the code
segment
f. END to indicate the termination of the program.