0% found this document useful (0 votes)
107 views8 pages

Assembly Language Programming

Assembly language is a low-level programming language that is specific to a particular computer architecture. It uses symbolic codes that are translated into machine language by an assembler program. Assembly language provides an understanding of how a computer works at the hardware level and allows for more efficient and hardware-specific programming compared to high-level languages. Developing assembly language programs involves writing source code, then using an editor, assembler, linker, debugger and other tools to translate, combine, test and debug the programs.

Uploaded by

Remmy Silver
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
107 views8 pages

Assembly Language Programming

Assembly language is a low-level programming language that is specific to a particular computer architecture. It uses symbolic codes that are translated into machine language by an assembler program. Assembly language provides an understanding of how a computer works at the hardware level and allows for more efficient and hardware-specific programming compared to high-level languages. Developing assembly language programs involves writing source code, then using an editor, assembler, linker, debugger and other tools to translate, combine, test and debug the programs.

Uploaded by

Remmy Silver
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

Assembly Language programming

Each family of processors has its own set of instructions for handling various operations like getting input
from keyboard, displaying information on screen and performing various other jobs.
These set of instructions are called 'machine language instruction'.
Processor understands only machine language instructions which are strings of 1s and 0s. However
machine language is too obscure and complex for using in software development. So the low level
assembly language is designed for a specific family of processors that represents various instructions in
symbolic code and a more understandable form
Assembly language is a low level programming language.

Assembly language is a low level programming language for a computer, or other programmable device
specific to a particular computer architecture.
This unlike most high-level programming languages, which are generally portable across multiple
systems.
Advantages of Assembly Language
 An understanding of assembly language provides knowledge of:
 Interface of programs with OS, processor and BIOS;
 Representation of data in memory and other external devices;
 How processor accesses and executes instruction;
 How instructions accesses and process data;
 How a program access external devices.
Other advantages of using assembly
 It requires less memory and execution time;
 It allows hardware-specific complex jobs in an easier way;
 It is suitable for time-critical jobs;
O. Juma 1|Page
 It is most suitable for writing interrupt service routines and other memory resident programs.
Assembly Language Program Development Tools
There are several tools available to support the programmer of assembly language for better experience of
programming. They are discussed in brief here:
• Editor
• Assembler
• Linker
• Locators
• Debuggers
• Emulators

Editor
It is the program which allows you to create a file containing the assembly language statements for your
program.
Examples are PC Write, Word stars and the editors that come with assemblers.
Creates Source file to be processed by the assembler
Assembler
It is the program which is used to transfer the assembly language mnemonics to corresponding binary
codes. It works in passes.
In the first pass, it determines the displacement of the named data items, the offset of labels etc. and puts
this information to in a symbol table.
In the second pass, it produces the binary codes for each instruction and inserts the offsets etc. that it
calculated in the first pass.
It generates two files namely object file (.OBJ) and assembler list file (.LST).
Linker
It is a program used to join several object files into large object files.
While writing large programs it is good to divide them into modules so that each modules can be written,
tested, debugged independently and then use linker to combine the modules to form the actual program.
It produces two files link file which contains the binary codes of all the combined modules and a link map
file which contains the address information about the linked files.
Locators
A locator is the program used to assign the specific addresses of where the segments of object code are to
be loaded in to main memory.
Examples include EXE2BIN which comes with the IBM PC DOS.
O. Juma 2|Page
Converts .exe to .bin files which has physical addresses

Debuggers
A debugger is the program which allows you to load your object code program in to system memory.
It allows you to look at the contents of the registers and memory locations after your program runs.
It also allows you to set breakpoints at any points in the program.
It simply allows you to find the source of the problem into the program.
There are lots of debuggers available like Borland Turbo Debugger, Microsoft’s Code view debugger etc.
Emulators
One way to run your program
It is mixture of hardware and software.
Generally used to test the hardware and software of an external system such as microprocessor based
instruments

Program Development Steps


1. Representing program operations
The problem that you want to solve
Just ask yourself question that “What do I really want this program to do?
2. Finding the right instructions
Formula or sequence of operations used to solve a programming problem is called as the
algorithm.
There are two ways of representing algorithms:
 Flowchart
It uses graphical shapes to represent different types of programming operations.
Flow chart symbols

O. Juma 3|Page
 Structured programming and pseudo code
Programs should be understandable to other programmers
Two approaches top-down and bottom up approach
Top-down: divide the program in to major modules and divide theses major
modules in to sub modules and so on.
Bottom-up: each programmer writes the low level module code and hopes
that all pieces will eventually fit together.
3. Writing a program
You need to do the following to write the program effectively:
a. INITIALIZATION INSTRUCTIONS: used to initialize various parts of the program like
segment registers, flags and programmable port devices.
b. STANDARD PROGRAM FORMAT: it’s a tabular format containing ADDRESS, DATA
OR CODE, LABELS, MNEM, OPERAND(S) and COMMENTS as the columns.
c. DOCUMENTATION: you should document the program. E.g. each page of the document
contains page number and name of the program, heading block containing the abstract
about the program, comments should be added wherever necessary.

Tips for Hand Coding 8086 Programs


• Check your algorithm very carefully to make sure that it really does what it supposed to do.
• Initially write down assembly language statements and comments for your program.
• Recheck each statement to make sure that you have right instructions to implement your
algorithm.
• Finally work out the binary code needed by each instruction and execute you program.

O. Juma 4|Page
Writing a program
To begin with, writing a program involves several steps (here are a few):
1. Define the external specification including the user interface and event handlers
2. Build the user interface
3. Code event handlers and write common code
4. Debug the program
5. Document the program

1. Defining the external specification of the program.


The first, most important and creative step. You cannot write the instructions for doing something until
you know what it is you want done, so before you start writing a program, you need a clear picture of
what it will do when it is finished.
You have to imagine it running -- what does the screen look like? What actions can the user take? What
happens when he or she takes each of those actions?
This step is analogous to an architect imagining then drawing pictures and plans for a house to be built.
The external description of a program should give enough detail that a programmer could use it to write
the program as you envisioned it.
You should prepare a written description, an external specification, of the program you are going to write
before you begin writing it.
For a short program, this description may be only one page long, but for a large program like Microsoft
Word, it would be very long and detailed.
The external specification should show the appearance of the user interface -- which controls are on the
screen and how they are laid out.
It should also specify the events that can occur -- the actions the user can take, and what the computer
should be programmed to do for each of them. (As we will see later, all events are not caused by user
action).
2. Build the user interface using the VS development system.
3. Code the event handlers. For each event you define in step 1, you must write an event handler, a
subprogram telling the computer what to do when that event occurs.
4. When you first run your program, it will not work properly. Debugging is the process of finding and
correcting your errors. In testing a program, you should give it extreme inputs in an attempt to force
errors.

O. Juma 5|Page
5. The job is not finished when the program is working correctly. The programmer must prepare
documents describing both the external specification and the internal design of the program. This
documentation will be of value to users and programmers who must maintain and modify your program.

Many people may work as a team if a project is large. There might be architects, programmers, testers and
documentation writers.
It may sound like you just work your way through these steps in order, but, in practice, you will find
yourself going back at times. For example, while writing event handlers, you might decide you need to
change the user interface, so you need to back up and change the external specification.
The best way to save time on a programming project is to spend a lot of time on the external design. A
well-designed program will be easy to code, debug and document. As they say "the best way to go fast is
to go slow."

Assembler Directives
There are some instructions in the assembly language program which are not a part of processor
instruction set. These instructions are instructions to the assembler, linker, and loader.
These are referred to as pseudo-operations or as assembler directives. The assembler directives enable we
to control the way in which a program assembles and lists.
They act during the assembly of a program and d not generate any executable machine code.
There are many specialized assembler directives. Let us see the commonly used assembler directive in
8086 assembly language programming.

ALIGN: The align directive forces the assembler to align the next segment at an address divisible by
specified divisor. The general format for these directives is as shown below.
ALIGN number
Where number can be 2, 4, 8 or 16
Example: ALIGN 8 this forces the assembler to align the next segment at Address that is divisible by 8.
The assembler fills the unused bytes with 0 for data and NOP instruction for code.
Usually ALIGN 2 directive is used to start the data segment on a word boundary and ALIGN 4 directive
is used to start the data segment on a double word boundary.

ASSUME : The 8086, at any time, can directly address four physical segments which include a code
segment, a data segment, a stack segment and an extra segment.

O. Juma 6|Page
The 8086 may contain a number of logical segments. The ASSUME directive assigns a logical segment to
a physical segment at any given time.
That is, the ASSUME directive tells the assembler what address will be in the segment registers at
execution time.
Example: ASSUME CS: code, DS: Data, SS: stack

CODE: This directive provides shortcut in definition of the code segment. General format for this
directive is as shown below.
The name is optional. It is basically specified to distinguish different code signets.
Code [name]

DATA: This directive provides shortcut in definition of the data segment.


DB, DW, DD, DQ, and DT: These directives are used to define diriment types of variables, or to set aside
one or more storage locations of corresponding data type in memory.
Their definitions are as follows:
DB – Define Byte
DW – Define Word
DD – Define Double word
DQ – Define Quad word
DT – Define Ten Bytes
Examples: AMOUNT DB 10H, 20H, 30H, 40H Declare array of 4 bytes named AMOUNTMES DB
‘WELCOME’
Declare array of 7 bytes and initialize with ASCII codes for letters in WELCOME

DUP: The DUP directive can be used to initialize several locations and to assign values to this location

END: The END directive is put after the last statement of a program to tell the assembler that this is the
end of the program module. The assembler ignores any statement after an END directive.

EQU: The EQU directive is used to redefine a data name or variable with another data name, variable, or
immediate value. The directive should be defined in a program before it is referenced.
Formats:
Numeric Equate Name EQU expression
String Equate Name EQU <string>
O. Juma 7|Page
Example: Two EQU Numeric value
NUM EQU <Enter the first number:’>

EXTRN: The EXTRFN directive is used to inform assembler that the names or labels following the
directive are in some other assembly module.
For example, if you want to call a procedure which is in a program module assembled at a different time,
you must tell the assembler that the procedure is EXTRN. The assembler will then put information in the
object code file so that the linker can connect the two modules together.

PUBLIC: Large programs are usually written as several separate modules. Each module is individually
assembled, tested and debugged.
When all the modules are working correctly, their object code files are linked together to form the
completer program. In order for the modules to link together correctly, and variable name or label referred
to in other modules must be declared public in the module where it is defined The PUBLIC directive is
used to tell the assembler that a specified name or label will be accessed from other modules.

8086-General Instruction Format

O. Juma 8|Page

You might also like