Вы находитесь на странице: 1из 52

N.

Senthil Kumar,
M. Saravanan &
S. Jeevananthan
Oxford University Press 2013
Oxford University Press 2013
Assembly Language
Programming of 8085
An assembler is a program used to translate assembly
language Mnemonics to the equivalent binary code for each
instruction.
Different assembler programs are available for different
processors because the assembly language for the different
processors is completely different.
The 8085 assembler program performs the task of
converting symbolic mnemonic code into binary object code
or machine code which can be executed by the 8085
microprocessors.
ASSEMBLER
Oxford University Press 2013
The assembler is a software tool or a program to be used
with the computers.
The object code or machine code file generated in the
computer system is then used in an 8085 based system.
ASSEMBLER contd..
Oxford University Press 2013
Assembler functional
diagram
Oxford University Press 2013
The input to the assembler is a file with the extension .asm.
The assembler output consists of at least two possible files.
a) The object or the hex file which contains the binary
machine code corresponding to each mnemonic in the source
assembly language program.
b) The list file containing the source assembly code along with
the corresponding machine code generated by the assembler
and the list of symbols used in the assembly program.

Description - Assembler
functional diagram
Oxford University Press 2013
Different types of assemblers are
a) the one pass assembler,
b) two pass assembler,
c) the macro assembler and
d) cross assembler.
In one pass assembler, the assembler takes the assembly
language program and processes it only once from start to
end.
In two pass assembler, the assembler, the assembler
processes the assembly language program twice once for
symbols and labels to assign memory locations for them and
then once again for the actual assembly process.
Types of Assembler
Oxford University Press 2013
The macro assembler is a program that translates assembly
language programs into machine code with the provision for
the programmer to define macro instructions.
Macros are user-defined abbreviations for particular
sequences of program routine.
When the program is assembled, each occurrence of the
macro is replaced by the instructions for which it stands.
Types of Assembler contd...
Oxford University Press 2013
Converting Assembly language program in to machine
language can be done manually if the assembly language
program is smaller.
But for large programs it becomes very difficult for manual
computation.
Hence assemblers are used to translate the assembly
language programs to machine language codes.
Need and advantages of
Assembler
Oxford University Press 2013
Assembly language programs provide the flexibility of using
the symbols for variables and constants used in the
program.
Assembler will then allocate memory locations for the
symbols used.
This simplifies the program development.
Also it is easy to change the values assigned to the symbols.
Assembler can reserve memory locations for the data,
results and arrays used in the program.

Need and advantages of
Assembler
Oxford University Press 2013
Assembly language program allows the programmer to use
the labels instead of physical addresses.
This feature offers the flexibility to specify jump address
indirectly and any change in the physical address can be
taken care of by assembler.
Need and advantages of
Assembler
Oxford University Press 2013
The assembler provides an option to start the program at
any physical address.
So, the programmer need not bother about the jump
addresses every time, the assembler will take care of it if
the starting address alone is given.
The assembler can assemble mnemonics into binary code
with high speed and accuracy, thus eliminating human
errors.
The assembler checks syntax errors, such as wrong labels,
opcodes, expressions, etc., and provide error messages.

Need and advantages of
Assembler
Oxford University Press 2013
The assembler directives are the instructions passed to the
assembler by the programmer.
It informs the assembler about the issues in the generation
of object code.
Generally, directives are also in the form of mnemonics and
can be placed anywhere in the assembly language program.

Assembler Directives
Oxford University Press 2013
Oxford University Press 2013
Assembler Directives
The assembler directives gives information like start and
end of a program; values of variables used in the program;
storage locations for input and output data; etc., to the
assembler.
The assembler directives are also called as pseudo
instructions because they just pass information to
assembler but not translated into machine code.
Assembler Directives
Oxford University Press 2013
Three assembler directive - ORG is placed at the starting of
the program and it defines where the machine language
program must be placed.
The start and end directives are used to indicate the start
and end of the assembly language program and so the
assembly process.
Assembler Directives -
Description
Oxford University Press 2013
The EQU directive is used to set the constants and assign a
value to it.
By using EQU statement, the programmer need not change
the constant value wherever it is used.
It is enough to change the EQU directive.
The DB, DW and DS directives are used to assign memory
locations to the variables and allocate the values to them.
Assembler Directives
Description contd..
Oxford University Press 2013
The 8085 instruction set contains about 74 different
instructions which are classified as data transfer
instructions, arithmetic instructions, logical instructions,
branch control instructions and machine control
instructions.
A good assembly language programmer must know all the
instructions of a microprocessor in order to write an
efficient and effective program.

Assembly Language
Programs
Oxford University Press 2013
To write a program,
a) the programmer first needs to understand the problem to
be solved by the program.
b)The programmer must clearly chart down the functional
objectives of the program along with inputs and the outputs
of the program.

Guidelines to writing
assembly language program
Oxford University Press 2013
The given problem should be broken down into small
functions or operations that can be programmed
independently.
This is called the modular design approach.
Subroutines are the functional subprograms written in
assembly language programs.
Guidelines to writing
assembly language program
Oxford University Press 2013
When a set of operations are repeated several times in a
program, it is efficient to write that set of operations as
subroutine.
Every subroutine is written with a specific operation and can
be called from the main program.
The programmer has to pass the arguments for the
subroutine properly
Guidelines to writing
assembly language program
Oxford University Press 2013
Writing a program is then writing specific instructions to the
microprocessor in a sequence to complete the preferred
operation.
The sequence of operations used to solve a problem is
called as algorithm.
A single problem can be solved by more than one ways,
meaning that there is more than one algorithm to solve a
programming problem.
Guidelines to writing
assembly language program
Oxford University Press 2013
The algorithm developed for a program can be written in
simple steps or can be easily represented in a diagrammatic
format called Flow chart.
Flow chart uses different shapes to represent the different
functions of a program.
Different shapes are available to represent different
operations like start of the program, Input/output
operation, process, subroutine, termination, etc.
Guidelines to writing
assembly language program
Oxford University Press 2013

The steps in writing assembly and machine language program
are given below.
a) Read the programming problem carefully.
b) Identify the input and output arguments for the program.


Steps to writing assembly
and machine language
program
Oxford University Press 2013
Oxford University Press 2013
Steps to writing assembly
and machine language
program
c) Break the problem down into small steps. If necessary, plan
for subroutines.
d) Represent these small steps in a possible sequence with a
flowchart.
e) Translate each block of the flowchart into appropriate
mnemonic instructions. Keep track of the variables and
memory locations used.

f) Convert the assembly language mnemonics into the
machine code either manually or using assembler.
g) Enter the machine code in memory and execute.
h) Start debugging the program


Steps to writing assembly
and machine language
program
Oxford University Press 2013

Arithmetic Operations
ADD: Add Add the contents of a register
ADI : Add immediate Add 8-bit data
SUB : Subtract Subtract the contents of a
register


Programming syntax for
simple arithmetic
operations
Oxford University Press 2013
Oxford University Press 2013
Programming syntax for
simple arithmetic operations
SUI : Subtract Immediate Subtract8- bit data
INR : Increment Increase the contents of a register
by 1
DCR: Decrement Decrease the contents of a register
by 1
ANA: AND Logically AND the contents of a register
ANI : AND Immediate Logically AND 8- bit data
ORA: OR Logically AND the contents of a register
ORI : OR Immediate Logically AND 8- bit data
XRA : EX-OR Exclusive - OR the contents of a register
XRI : EX OR Immediate Exclusive - OR 8-bit data

Programming syntax for
simple logical operations
Oxford University Press 2013
Branch Operations
a) The microprocessors use Von Neumann architecture and
execute machine codes from one memory location to the next
in a sequential manner.
b) The branching instructions are the most useful instructions
to allow the microprocessor to change the location of the
execution of a program from its regular sequential position.
Branching Operations
Oxford University Press 2013
Branch instructions instruct the microprocessor to go to a
different memory location and continue executing machine
codes from that new location.
This type of jumping can be done either unconditionally or
conditionally testing the flags.
Branching operations
contd..
Oxford University Press 2013
The branch instructions can be any one of the following
three categories:
a) Jump instructions
b) Call and Return instructions
c) Restart instructions

Branch Instructions - types
Oxford University Press 2013
The Jump instructions will transfer the control of the
processor execution to the jump address defined by the
programmer permanently.
Subroutine Call instructions on the other hand, provide the
flexibility to jump to the address provided by the
programmer and then to return the address from where it
was called.
The Restart instructions will jump to the address decided by
the internal hardware of the processor.
Branch Instructions
Oxford University Press 2013
The programming languages use any one of the three basic
structure if-then-else, while-do and repeat-until in
addition to the sequential structure.
The while-do and repeat-until structure use the technique
to repeat the tasks called looping.
A loop is set up by instructing the microprocessor to execute
a task and then change the sequence of execution and
perform the task again.
This process is accomplished by using Jump instructions.
Loop Operations
Oxford University Press 2013

Techniques such as counting and indexing are used in
setting up a loop.
Loops can be classified into two groups:
a) While do Continuous loop repeats a task if a condition is
satisfied
b) Repeat-until Conditional loop repeats a task until certain
data conditions are met. This is similar to the FOR loop of high
level languages.

Loop Operations contd..
Oxford University Press 2013
In microprocessor applications, various number systems and
codes are used for representing data.
Inside the microprocessor hardware, data is processed as if
it is binary.
But, the instruction set of the 8085 processor provides the
flexibility of handling data in BCD format or in signed
format.
Code Conversion, Decimal
Arithmetic and Bit
Manipulations
Oxford University Press 2013

Similarly, the text data also has different forms
representation such as ASCII code, Excess 3 code etc.
There are instances in which data need to be converted
from one code another code.

Code Conversion, Decimal
Arithmetic and Bit
Manipulations contd..
Oxford University Press 2013
Oxford University Press 2013
Code Conversion, Decimal
Arithmetic and Bit
Manipulations contd..
The programming techniques used for code conversion fall
into three general categories:
a) Conversion based on the number system followed in a
number (BCD to binary and vice versa).
b) Conversion based on hardware requirement (binary to
seven segment code using look up procedure).
c) Conversion based on text format of digits (binary to ASCII
and vice versa).
Subroutine is a group of instructions that are written to
perform a specific task.
The subroutine can be called by a main program many times
repeatedly as and when required.
This simplifies the main program as it can eliminate the
code to be rewritten repeatedly every time.
For example in order to find the factorial, multiplication
routine has to written many times.
Subroutine concepts
Oxford University Press 2013
But instead we can write a subroutine for multiplication and
can call this repeatedly to find the factorial.
The subroutine makes use of stack to return to the main
program after the subroutine is over. The stack is used to
store the return address whenever the subroutine is called.
The instructions used for subroutine call and return are
CALL and RET in 8085.
The other conditional call and return instructions of 8085
are explained in the previous chapter.



Subroutine concepts
Oxford University Press 2013
The important aspects to be considered while developing
subroutine are listed below.
a) Parameter passing: The subroutines are written for
performing a specific task. It is necessary to pass the
arguments or the variables to this subroutine from the main
program. In 8085 programming, the variables are passed to
the subroutine through the registers.
Subroutine concepts
Oxford University Press 2013

b) Use of stack: The subroutine in addition to the registers
used for parameter passing may require some more registers.
But the main program may have stored some data in these
registers. So, care must be taken in the subroutine not to
affect the register contents of the CPU in the subroutine. This
can be safely done by storing the processor register contents
on to the stack before using that register in the subroutine.
Then at the end of the subroutine, these register contents can
be replaced in to the corresponding registers from the stack.

Subroutine concepts
Oxford University Press 2013
c) Proper use of Stack: The processor register contents can be
stored on to the stack. But it must be remembered that stack
is Last In First Out array of registers. So, the data retrieved
from the stack is in the reverse order in which it was stored.
This way we can safely handle the data.
Subroutine concepts
Oxford University Press 2013

d) Retaining return address: The processor also uses stack to
store the return address in the main program whenever the
subroutines are called. So, the stack content at the entry of
subroutine must be same at the exit of subroutine. This can
be ensured only if there are equal number of PUSH and POP
instructions within the subroutine. This is very important
because otherwise, the return address will be disturbed and
the program execution may become erratic.

Oxford University Press 2013
Subroutine concepts
Timing Delay: Timing of events in a microprocessor is very
important.
Many applications of microprocessor require some periodic
actions.
One example for such timing is in data acquisition.

Time Delays
Oxford University Press 2013
Oxford University Press 2013
Time Delays
It is customary to acquire data from the sensors in an
industrial environment at regular intervals and store it in
memory.
It may be necessary to read temperature after every second
and store it in memory continuously.
So, it is required to maintain timing in microprocessor by
some means.
There are many techniques to keep up this timing and
delays. First simplest method is by software.
A software time delay is designed by loading a register with
a delay count and setting up a loop to decrement the count
until zero.
The total time delay produced is determined by the clock
period of the system and the time required for executing
instructions in the loop.

Time Delays
Oxford University Press 2013
Oxford University Press 2013
Time Delays
This is also called as software counter or timer.
Counters and time delays are important techniques.
They are commonly used in applications such as traffic
signals, digital clocks, process control and serial data
transfer.
Opcode: The part of the instruction that specifies the
operation to be performed is called the operation code or
opcode.
Operand: The data on which the operation is to be
performed is called as an Operand.
Key terms
Oxford University Press 2013
Oxford University Press 2013
Key terms
Assembler: The assembler translates the assembly language
program text which is given as input to the assembler to
their binary equivalents known as object code. The time
required to translate the assembly code to object code is
called access time. The assembler checks for syntax errors &
displays them before giving the object code.
Assembly Language: The language in which the mnemonics
(short -hand form of instructions) are used to write a
program is called assembly language. The manufacturers of
microprocessor give the mnemonics.


Machine Language program: The software developed using
1s and 0s are called machine language, programs.
Arithmetic operations: The 8085 microprocessor performs
various arithmetic operations, such as addition, subtraction,
increment and decrement.
Logical Operations: A microprocessor is basically a
programmable logic chip. It can perform all the logic
functions of the hard wired logic through its instruction set.
The 8085 instruction set includes such logic functions as
AND, OR, EX OR and NOT.

Key terms contd..
Oxford University Press 2013

Branch operations: The microprocessor is a sequential
machine, executes machine codes from one memory
location to the next.
Branch instructions instruct the microprocessor to go to a
different memory location and the microprocessor
continues executing machine codes from that new location.
The address of the new memory location is either specified
explicitly or supplied by the microprocessor or by extra
hardware.
Looping: The programming technique used to instruct the
microprocessor to repeat tasks is called looping.

Key terms contd..
Oxford University Press 2013

Вам также может понравиться