0% found this document useful (0 votes)
3 views40 pages

CH 2

The document outlines the fundamentals of assembly language programming, including the steps for program development, writing algorithms, and using flowcharts. It discusses essential tools such as editors, assemblers, linkers, and debuggers, as well as various assembler directives with examples. The content serves as a comprehensive guide for students learning assembly language at Government Polytechnic, Jintur.

Uploaded by

sushyask888
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views40 pages

CH 2

The document outlines the fundamentals of assembly language programming, including the steps for program development, writing algorithms, and using flowcharts. It discusses essential tools such as editors, assemblers, linkers, and debuggers, as well as various assembler directives with examples. The content serves as a comprehensive guide for students learning assembly language at Government Polytechnic, Jintur.

Uploaded by

sushyask888
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

THE ART OF ASSEMBLY LANGUAGE

PROGRAMMING
By
Ritesh V Navgaje
Lecturer Instrumentation
Government Polytechnic, Jintur

CO-4I MIC (22415)


Government Polytechnic Jintur
COURSE OUTCOME
 Write assembly language program for the given problem.

CO-4I MIC (22415)


Government Polytechnic Jintur
UNIT OUTCOME
 Describe the given steps of program development / execution.
 Write steps to develop a code for the given problem using
assembly language programming.
 Use relevant command of debugger to correct the specified
programming error.
 Describe function of the given assembler directives with example.

CO-4I MIC (22415)


Government Polytechnic Jintur
Content
 Program development steps
 Defining problem,
 Writing Algorithms
 Flowchart
 Initialization checklist
 Choosing instructions
 Converting algorithms to assembly language programs. 08
 Assembly Language Programming Tools Marks
 Editors
 Assembler
 Linker
 Debugger.
 Assembler directives
CO-4I MIC (22415)
Government Polytechnic Jintur
DEFINING PROBLEM
 In almost every problem solving methodology the first step is defining or
identifying the problem.
 It is the most difficult and the most important of all the steps.
 It involves diagnosing the situation so that the focus on the real problem and not on
its symptoms
 Sometimes problem definition may be nothing more than the art of asking the right
questions at the right time.

CO-4I MIC (22415)


Government Polytechnic Jintur
WRITING ALGORITHMS
 An algorithm is an effective method for solving a problem expressed as a finite
sequence of instructions.
 It is usually a high-level description of a procedure which manipulates well-defined
input data to produce other data
 There are many ways to write algorithms (charts, imperative program, equations, ...)
 An algorithm takes an input and produces an output

CO-4I MIC (22415)


Government Polytechnic Jintur
FLOWCHART
 A flowchart is a formalized graphic representation of a logic sequence, work or
manufacturing process, organization chart, or similar formalized structure.
 Flowcharts use simple geometric symbols and arrows to define relationships.
 In programming, for instance,
 the beginning or end of a program is represented by an oval.
 A process is represented by a rectangle,
 A decision is represented by a diamond
 An I/O process is represented by a parallelogram. The Internet is represented by a
cloud.

CO-4I MIC (22415)


Government Polytechnic Jintur
CO-4I MIC (22415)
Government Polytechnic Jintur
CO-4I MIC (22415)
Government Polytechnic Jintur
Cont…
 Initialization checklist
 Initialization task is to make the checklist of entire variables,
constants, all the registers, flags and programmable ports
 Choosing instructions
 Choose those instructions that make program smaller in size and
more importantly efficient in execution.
 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.

CO-4I MIC (22415)


Government Polytechnic Jintur
ASSEMBLY LANGUAGE
 Assembly language is the lowest level of symbolic programming for a computer
system.
 Assembly language requires an understanding of the machine architecture, and
provides huge flexibility in developing hardware/software interface programs such
as interrupt service routines, and device drivers
 8086 Turbo Assembler(TASM) is one of the well known assembler programs
used for PC-XT and AT family computers.

CO-4I MIC (22415)


Government Polytechnic Jintur
Assembly Language Programming Tools
 Editors
 Assembler
 Linker
 Debugger

CO-4I MIC (22415)


Government Polytechnic Jintur
EDITORS
 It is a program which when run on a computer system allows one to type or edit
assembly language program statements
 It enables one to create, edit, save, copy and make modification in the source files
 The file created by the editor is in an ASCII format and is know as the source file
 To create source file in TASM type edit on command prompt, a menu based blue
text editor screen appears on the screen

CO-4I MIC (22415)


Government Polytechnic Jintur
ASSEMBLER
 A programming tool used to convert an Assembly Language Program statements
into machine language program
 The C for x86 families of processor are TASM/MASM/NASM
 If there are errors left in assembled .ASM program .OBJ will not be created
 In TASM C:\TASM\TASM [Link]
 Assembler will create .OBJ, .LST, .CRF files

CO-4I MIC (22415)


Government Polytechnic Jintur
LINKER
 It is used to convert object code/program into executable code/program
 The object files contains the program code but some of the labels are still in
symbolic form.
 A linker converts them into the executable file replacing all symbols with their
corresponding values.
 It requires input as Object Code(.OBJ)
 It generate .EXE module and initializes it with special instruction to facilitate its
subsequent loading for execution
 In TASM C:\TASM\TLINK [Link]

CO-4I MIC (22415)


Government Polytechnic Jintur
DEBUGGER
 It is this debug program which is part of Disk Operating System (DOS),that
permits us to initiate various stages of assembly language programming from the
keyboard of our computer.
 It gives a convenient view of the CPU status, and the memory segments.
 The debugger is sometimes called a "mini-assembler," because it allows the user to
create and run short or small assembly language programs.
 With the debugger, the user can access the system's main memory and save the
program directly on the disk without the intervention of the DOS.
 the debugger can be used to disassemble object codes (machine instructions) into
readable codes

CO-4I MIC (22415)


Government Polytechnic Jintur
ASSEMBLER DIRECTIVES
 They are direction to the assembler
 They are the commands to the assembler that direct the assembly process.
 They indicate how an operand is treated by the assembler and how assembler
handles the program.
 They also direct the assembler how program and data should be arranged in the
memory.

CO-4I MIC (22415)


Government Polytechnic Jintur
DB
 Define Byte
 Define a byte type (8-bit) variable
 Reserves specific amount of memory locations to each variable
 Range :
 00H – FFH for unsigned value;
 00H – 7FH for positive value and
 80H – FFH for negative value
 General form : variable DB value/ values

CO-4I MIC (22415)


Government Polytechnic Jintur
DW
 Define Word
 Define a word type (16-bit) variable
 Reserves two consecutive memory locations to each variable
 Range :
 0000H – FFFFH for unsigned value
 0000H – 7FFFH for positive value and
 8000H – FFFFH for negative value
 General form : variable DW value/ values

CO-4I MIC (22415)


Government Polytechnic Jintur
DD
 Define Double Word
 Define a double word type (32-bit) variable
 Reserves four consecutive memory locations to each variable
 General form : variable DD value/ values

CO-4I MIC (22415)


Government Polytechnic Jintur
DQ
 DEFINE QUADWORD
 The DQ directive is used to tell the assembler to declare a variable 4 words in
length or to reserve 4 words of storage in memory.
 Example:
BIG_NUMBER DQ 243598740192A92B H

This will declare a variable named BIG_NUMBER and initialize the 4 words set
aside with the specified number when the program is loaded into memory to be
run.

CO-4I MIC (22415)


Government Polytechnic Jintur
DUP
 Duplicate memory location
 This directive can be used to generate multiple bytes or words
with known as well as un-initialized values.

CO-4I MIC (22415)


Government Polytechnic Jintur
SEGMENT
 The SEGMENT directive is used to indicate the start of a logical segment.
 Preceding the SEGMENT directive is the name you want to give the segment.
 For example, the statement CODE SEGMENT indicates to the assembler the start
of a logical segment called CODE.
 The SEGMENT and ENDS directive are used to “bracket” a logical segment
containing code of data.
 Name SEGMENT
Variable_name DB …….
Variable_name DW …….
Name ENDS

CO-4I MIC (22415)


Government Polytechnic Jintur
ENDS
 END SEGMENT
 This directive is used with the name of a segment to indicate the end of that logical
segment.
 CODE SEGMENT; Start of logical segment containing code instruction statements
 CODE ENDS; End of segment named CODE

CO-4I MIC (22415)


Government Polytechnic Jintur
ASSUME
 ASSUME tells the assembler what names have been chosen for Code, Data Extra
and Stack segments.
 Informs the assembler that the register CS is to be initialized with the address
allotted by the loader to the label CODE and DS is similarly initialized with the
address of label DATA.
 Example
 ASSUME CS: Name of code segment
 ASSUME DS: Name of the data segment
 ASSUME CS: Code1, DS: Data1

CO-4I MIC (22415)


Government Polytechnic Jintur
EQU
 EQUATE
 EQU is used to give a name to some value or symbol.
 Each time the assembler finds the given name in the program, it replaces the name
with the value or symbol you equated with that name.
 Example
Data SEGMENT
Num1 EQU 50H
Num2 EQU 66H
Data ENDS
 Numeric value 50H and 66H are assigned to Num1 and Num2

CO-4I MIC (22415)


Government Polytechnic Jintur
PROC
 PROCEDURE
 The PROC directive is used to identify the start of a procedure.
 The PROC directive follows a name you give the procedure. After the PROC directive, the term near or the
term far is used to specify the type of the procedure
 Example:
DIVIDE PROC FAR
 This identifies the start of a procedure named DIVIDE and tells the assembler that the procedure is far (in a
segment with different name from the one that contains the instructions which calls the procedure).
 The PROC directive is used with the ENDP directive to “bracket” a procedure
 NEAR: the procedure resides in the same code segment. (Local)
 FAR: resides at any location in the memory.
 Example
Add PROC NEAR
ADD AX,BX
MOV CX,AX
RET
Add ENDP
 PROC directive stores the contents of the register in the stack.
CO-4I MIC (22415)
Government Polytechnic Jintur
ENDP
 END PROCEDURE
 The directive is used along with the name of the procedure to indicate the end of a
procedure to the assembler.
 The directive, together with the procedure directive, PROC, is used to “bracket” a
procedure.
 Example:
SQUARE_ROOT PROC; Start of procedure.
SQUARE_ROOT ENDP; End of procedure.

CO-4I MIC (22415)


Government Polytechnic Jintur
LENGTH
 LENGTH is an operator, which tells the assembler to determine the number of
elements in some named data item, such as a string or an array.
 Example: MOV CX, LENGTH STRING1
 This will determine the number of elements in STRING1 and load it into CX.
 If the string was declared as a string of bytes, LENGTH will produce the number
of bytes in the string.
 If the string was declared as a word string, LENGTH will produce the number of
words in the string.

CO-4I MIC (22415)


Government Polytechnic Jintur
OFFSET
 OFFSET is an operator, which tells the assembler to determine the offset or
displacement of a named data item (variable), a procedure from the start of the
segment, which contains it.
 Example:
MOV BX,OFFSET PRICES
 It will determine the offset of the variable PRICES from the start of the segment in
which PRICES is defined and will load this value into BX.

CO-4I MIC (22415)


Government Polytechnic Jintur
ORG
 Originate
 The directive ORG assigns the location counter with value specified in the
directive.
 It helps in placing the machine code in the specified location while translating
instructions into machine codes by the assembler.
 $ is used to indicate current value of location counter
 Example:
 ORG 2000H ; set location counter to 2000H
 ORG $+100 ; increment value of location counter by

CO-4I MIC (22415)


Government Polytechnic Jintur
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.
 The name of the include file follows the statement INCLUDE

CO-4I MIC (22415)


Government Polytechnic Jintur
NAME
 The NAME directive is used to give a specific name to each assembly module when
programs consisting of several modules are written.

CO-4I MIC (22415)


Government Polytechnic Jintur
LABEL
 As an assembler assembles a section of a data declarations or instruction statements, it
uses a location counter to be keep track of how many bytes it is from the start of a
segment at any time.
 The LABEL directive is used to give a name to the current value in the location counter.
 The LABEL directive must be followed by a term that specifics the type you want to
associate with that name.
 If the label is going to be used as the destination for a jump or a call, then the label must
be specified as type near or type far.
 Example
 ENTRY_POINT LABEL FAR; Can jump to here from another segment
 NEXT: MOV AL, BL; Can not do a far jump directly to a label with a colon

CO-4I MIC (22415)


Government Polytechnic Jintur
TYPE
 TYPE - instructs the assembler to determine the type of a variable and determines
the number of bytes specified to that variable.
 Example:
 Byte type variable – assembler will give a value
 1 Word type variable – assembler will give a value
 2 Double word type variable – assembler will give a value 4

CO-4I MIC (22415)


Government Polytechnic Jintur
PTR
 POINTER : used to assign a specific type to a variable or a label. It is necessary to
do this in any instruction where the type of the operand is not clear.
 Example:
 INC [BX]; It will not know whether to increment the byte pointed to by BX. We use
the PTR operator to clarify how we want the assembler to code the instruction.
 INC BYTE PTR [BX] ; This statement tells the assembler that we want to increment the
byte pointed to by BX.
 INC WORD PTR [BX] ; This statement tells the assembler that we want to increment
the word pointed to by BX. The PTR operator assigns the type specified before PTR to
the variable specified after PTR.

CO-4I MIC (22415)


Government Polytechnic Jintur
EVEN
 The EVEN directive updates the location counter to the next even address if the current location counter
contents are not even, and assigns the following routine or variable or constant to that address.
 The structure given below explains the directive.
EVEN
PROCEDURE ROOT
.
.
ROOT ENDP
 The assembler will start assembling the main program calling ROOT.
 When the assembler comes across the directive EVEN, it checks the contents of the location counter.
 If it is odd, it is updated to the next even value and then the ROOT procedure is assigned to that address
 If the content of the location counter is already even, then the ROOT procedure will be assigned with the
same address

CO-4I MIC (22415)


Government Polytechnic Jintur
Summary
 We learn about….
 Program development steps
 Defining problem,
 Writing Algorithms
 Flowchart
 Initialization checklist
 Choosing instructions
 Converting algorithms to assembly language programs.
 Assembly Language Programming Tools
 Editors
 Assembler
 Linker
 Debugger.
 Assembler directives
Unit Outcome / Course Outcome
 Describe the given steps of program development / execution.
 Write steps to develop a code for the given problem using assembly
language programming.
 Use relevant command of debugger to correct the specified programming
error.
 Describe function of the given assembler directives with example.

 Write assembly language program for the given problem.


THANK YOU!!!
HAPPY LEARNING

Ritesh V Navagaje
Lecturer Instrumentation
Government Polytechnic Jintur
Email: navgaje_rit@[Link]
Mobile: 9420070466
CO-4I MIC (22415)
Government Polytechnic Jintur

You might also like