0% found this document useful (0 votes)
3 views

Microprocessor Unit 4 Notes (1) (1)

The document provides comprehensive notes on assembly language programming for the Intel 8085/8086 microprocessors, covering instruction sets, data transfer, arithmetic, logic, and branch operations. It also details programming techniques such as looping, counting, indexing, and code conversion, alongside methods for implementing counters and time delays. Additionally, it explains the stack structure and subroutine management in the context of microprocessor operations.

Uploaded by

om0405202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Microprocessor Unit 4 Notes (1) (1)

The document provides comprehensive notes on assembly language programming for the Intel 8085/8086 microprocessors, covering instruction sets, data transfer, arithmetic, logic, and branch operations. It also details programming techniques such as looping, counting, indexing, and code conversion, alongside methods for implementing counters and time delays. Additionally, it explains the stack structure and subroutine management in the context of microprocessor operations.

Uploaded by

om0405202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Microprocessor Unit 4 Notes

-Compiled by: Prof. Minakshi

Assembly language programming based on Intel 8085/8086, Instructions, data


transfer, arithmetic, logic, branch operations, looping, counting, indexing,
programming techniques, counters and time delays, stacks and subroutines,
conditional call and return instructions.

INTEL 8085/8086 INSTRUCTION SET


I have already uploaded on the moodle. You can find the 8085 instruction set
and 8086 instruction set there.

8085 Various Operations:


 Data Transfer Operations
 Arithmetic Operations
 Logic Operations
 Branch Operations
DATA TRANSFER OPERATIONS
The primary function of the microprocessor is copying data, from a register (or
I/O or memory called the source, to another to the register (or I/O or memory)
called the destination.
The data transfer instructions copy the data from a source into a destination
without modifying the contents of the source.
Some of data transfer instructions:
MOV Rd, Rs
MVI R, 8-bit
IN 8-bit port address
OUT 8-bit port address
ARITHMETIC OPERATIONS
The microprocessor performs various arithmetic operations such as addition,
subtraction, increment and decrement.
Some of the arithmetic instructions:
ADD R
ADI 8-bit
SUB
SUI 8-bit
INR R
DCR R
These instructions except INR, DCR
 Assume implicitly that one operand is Accumulator.
 Modify the all the flags according to the data conditions of the result
 Place the result in the accumulator
 Do not affect the contents of the operand register.

LOGIC OPERATIONS
The microprocessor 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. Some logic instructions are:
ANA R
ANI 8-bit
ORA R
ORI 8-bit
XRA R
XRI 8-bit
CMA
These instructions
 Assume implicitly that one operand is Accumulator.
 Reset the CY flag. The CMA instruction does not affect any flag.
 Modify the Z, P, S flags according to the data conditions of the result
 Place the result in the accumulator
 Do not affect the contents of the operand register.
BRANCH OPERATIONS:
Branch operations allow the microprocessor to change the sequence of the
program either unconditionally or under certain test conditions.
The microprocessor is a sequential machine; it executes machine codes from
one memory location to the next. Branch instructions instruct microprocessor to
the different memory location, and the microprocessor continues executing the
machine codes from that new location. The branch instructions are classified
into three categories:
 Jump instructions
 Call and return instructions
 Restart instructions

JUMP INSTRUCTIONS:
Unconditional Jump:
Unconditional Jump JMP instruction enables the programmer to set up a
continuous loop.
Conditional Jump:
– JC, jumps if Carry flag is set
– JNC, jumps if Carry flag is not set. Etc
– JZ, jumps if zero flag is set.
– JNZ, jumps if zero flag is not set
– JM, jumps if sign flag is set. (Sign=1 negative number)
– JP, jumps if sign flag is not set. (sign =0 positive number)
–JPE, jumps if parity flag is set. (P=1 even parity)
–JPO, jumps if parity flag is not set. (P=0 odd parity)
CALL AND RETURN INSTRUCTIONS
The 8085 supports conditional CALL and conditional RET instructions.
Conditional CALL:
– CC, calls subroutine if Carry flag is set.
– CNC, call subroutine if Carry flag is not set
– CZ, calls subroutine if zero flag is set.
– CNZ, call subroutine if zero flag is not set
– CM, calls subroutine if sign flag is set. (sign=1 negative number)
– CP, call subroutine if sign flag is not set (sign =0 positive number)

Conditional Return:
– RC, returns from subroutine if Carry flag is set
– RNC, returns from subroutine if Carry flag is not set. Etc
– RZ, returns subroutine if zero flag is set.
– RNZ, returns subroutine if zero flag is not set
– RM, returns subroutine if sign flag is set. (Sign=1 negative number)
– RP, returns subroutine if sign flag is not set. (sign =0 positive number)
–RPE, returns subroutine if parity flag is set. (P=1 even parity)
–RPO, returns subroutine if parity flag is not set. (P=0
Restart instructions:
RST instructions are the 1-byte Call instructions that transfer the program
execution to a specific location on page 00H.
When an RST instruction is executed, the 8085 stores the contents of the
program counter on the top of stack and transfer the program to restart location.
These instructions are generally used in conjunction with interrupt process.
Eight RST instructions are:
RST 0 Call 0000H
RST 1 Call 0008H
RST 2 Call 0010H
RST 3 Call 0018H
RST 4 Call 0020H
RST5 Call 0028H
RST 6 Call 0030H
RST 7 Call 0038H
PROGRAMMING TECHNIQUES
 Looping
 Counting
 Indexing
The program is an implementation of certain logic by executing group of
instructions. To implement program logic, we need to take help of some
common Programming Techniques such as looping, counting, and indexing
Looping:
This programming technique using 8085 is instructed to execute certain set of
instructions repeatedly to perform a particular task number of times. For
example, to add ten numbers stored in the consecutive memory locations we
have to perform addition ten times.
Counting:
This technique allows programmer to count how many times the instruction/set
of instructions are executed.
Indexing:
This technique allows programmer to point or refer the data stored in sequential
memory locations one by one.

Example:
Illustrate the steps needed to add 10 bytes of data stored in memory locations
staring at a given location, and display the sum.
Procedure: the microprocessor needs:
 A counter to count 10 data bytes
 An index or a memory pointer to locate where data bytes are stored
 To transfer the data from a memory location to microprocessor (ALU)
 To perform addition
 Registers for temporary storage of partial answers
 A flag to indicate the completion of task
 To store or output the result
The Programming Techniques using 8085 loop is the basic structure which
forces the processor to repeat a sequence of instructions.
There are two types of loops:
 Continuous loop-repeat task continuously
 Conditional loop-repeats a task until certain data conditions are met
Continuous loop: A Continuous loop is set up by using the unconditional Jump
JMP instruction.

A Conditional loop is set up by the conditional jump instructions. These


instructions check flags (zero, sign, and parity etc.) and repeat the specified task
if condition is met.
Loops have four sections.
 Initialization section.
 Processing section.
 Loop control section
 Result section.
1. The initialization section establishes the starting values of
 loop counters for counting how many times loop is executed,
 address registers for indexing which give pointers to memory locations
and
 other variables
2. The actual data manipulation occurs in the processing section. This is the
section which does the work.
3. The loop control section updates counters, indices (pointers) for the next
4. The result section analyzes and stores the results.
Code Conversion:
This programming technique in 8085 to translate a number represented using
one coding system to another. For example, when we accept any number from
the keyboard it is in ASCII code. But for processing, we have to convert this
number in its hex equivalent. The code conversion involves some basic
conversions such as
 BCD to Binary conversion
 Binary to BCD conversion
 BCD to seven segment code conversion
 Binary to ASCII conversion and
 ASCII to binary conversion

BCD to Binary Conversion:


We are more familiar with the decimal number system. But the microprocessor
understands the binary/hex number system. To convert BCD number into its
binary equivalent we have to use the principle of positional weighting in a given
number.

To perform above operation it is necessary to separate an 8-bit packed BCD


number into two 4-bit unpacked BCD digits: BCD1 and BCD2 and then convert
each digit into its binary value according to its positions. Finally, add both
binary numbers to obtain the binary equivalent of the BCD number. Let us see
the program for 2-digit BCD to binary conversion.

Binary to BCD Conversion:


We know that microprocessor processes data in the binary form. But when it is
displayed, it is in the BCD form. In this case we need binary to BCD conversion
of data. The conversion of binary to BCD is performed by dividing the number
by the power of ten.
BCD to Seven Segment Conversion:
Many times 7-segment LED display is used to display the results or parameters
in the microprocessor system. In such cases we have to convert the result or
parameter in 7-segment code. This conversion can be done using look-up
technique. In the look-up table the codes of the digits (0-9) to be displayed are
stored sequentially in the memory. The conversion program locates the code of
a digit based on its BCD digit. Let us see the Programming Techniques using
8085 for BCD to common cathode 7-segment code conversion.

Binary to ASCII Code Conversion:


The ASCII Code (American Standard Code for Information Interchange) is
commonly used for communication. In such cases we need to convert binary
number to its ASCII equivalent. It is a seven bit code. In this code number 0
through 9 are represented as 30 through 39 respectively and letters A through Z
are represented as 41H through 5AH. Therefore, by adding 30H we can convert
number into its ASCII equivalent and by adding 37H we can convert letter to its
ASCII equivalent. Let us see the Programming Techniques in 8085 for binary to
ASCII code conversion.

ASCII Code to Binary Conversion:


It is exactly reverse process to binary to ASCII conversion. Here, if ASCII code
is less than 3AH then 30H is subtracted to get the binary equivalent and if it is
in between 41H and 5AH then 37H is subtracted to get the binary equivalent of
letter (A-F).
COUNTERS AND TIME DELAYS
COUNTER:
A counter is designed simply by loading appropriate number into one of the
registers and using INR or DCR instructions.
• Loop is established to update the count.
• Each count is checked to determine whether it has reached final number; if
not, the loop is repeated.
TIME DELAY:

Why Time delays?


In the real time applications, such as traffic light control, digital clock, process
control, serial communication, it is important to keep a track with time. For
example in traffic light control application, it is necessary to give time delays
between two transitions. These time delays are in few seconds and can be
generated with the help of executing group of instructions number of times.
These software timers are also called time delays or software delays.
As you know microprocessor system consists of two basic components,
Hardware and software. The software component controls and operates the
hardware to get the desired output with the help of instructions. To execute
these instructions, microprocessor takes fix time as per the instruction, since it is
driven by constant frequency clock. This makes it possible to introduce delay
for specific time between two events.

TIME DELAY:
The procedure used to design a specific delay is similar to that used to set up a
counter.
A register is loaded with a number, depending on the time delay required, and
then the register is decremented until it reaches zero by setting up a loop with
conditional jump instruction. The loop causes a delay, depending upon the clock
period of the system.
We can design time delay using following three techniques:
 Time delay using one register
 Time delay using register pair
 Time delay using a loop within a loop
Time delay using one register:
A count is loaded in a register and the loop is executed until the count reaches to
zero. The flowchart has been shown below:

Time delay Formulas:


Total delay TD = Time to execute instructions outside loop (T O) + Time to execute loop instructions (T L)

Time required to execute an instruction= number of T-states* clock period

Clock frequency of the system f

Clock period T= 1/f

Time Delay in Loop TL= T*Loop T states * N10

N10 = Equivalent decimal number of hexadecimal count loaded in the delay register
Example:
Label opcode operand Description T-state

Clock frequency of the system f = 2 MHz


Clock period= 1/f= 1/2 = 0.5 μs
Time to execute MVI = T-state for MVI*clock period
TO =7 T states * 0.5
= 3.5 μs

Time Delay in Loop TL= T*Loop T states * N10


= 0.5 * 14* 255
= 1785 μs
= 1.8 ms
Note: 255 is equivalent decimal number of hexadecimal count FF loaded in the
register C.
Note: T-states for JNZ instruction are shown as 10/7. The 8085 microprocessor
requires 10 T-states to execute a conditional jump when it jumps and seven T-
states when in the last iteration, JNZ will fail (C reaches to zero).

The adjusted loop delay TLA= Time to execute loop instructions


=TL – (3T states* clock period)
=1785- 3*.5
=1785-1.5
=1783.5 μs
Note: the difference between loop delay and adjusted loop delay is approax 2 μs
Hence it can be ignored in some cases.
Total delay TD = Time to execute instructions outside loop (T O) + Time to execute loop instructions (T L)

= TO+TLA
= 3.5+1783.5
=1787 μs

TIME DELAY USING A REGISTER PAIR:


The time delay can be increased by setting a loop and using a register pair with
a 16-bit number (maximum FFFF H). The 16-bit number is decremented using
DCX instruction. However the, instruction DCX does not set the zero flag. So,
additional techniques must be used to set the zero flag.
Example:

Clock frequency of the system f = 2 MHz


Clock period= 1/f= 1/2 = 0.5 μs
Decimal equivalent of 2384 H = 909210
Time to execute LXI = T-state for LXI*clock period
TO =10T states * 0.5
=5 μs
Time Delay in Loop TL= T*Loop T states * N10
=0.5*24*9092
=109104 μs
=109 ms
Example: Time Delay using a LOOP within a LOOP

Delay in Loop TL1=1783.5 μs


56 is the decimal equivalent of 38 hexadecimal value.
Delay in Loop TL2= (0.5*21+TL1)*56
= 100.46ms
Timer Delay Using NOP Instruction:
NOP instruction does nothing but takes 4T states of processor time to execute.
So by executing NOP instruction in between two instructions we can get delay
of 4 T-state
STACKS AND SUBROUTINES

STACK:
The stack is an area of memory identified by the programmer for temporary
storage of information.
• The stack is a LIFO structure- Last In First Out.
• The stack normally grows backwards into memory.
– In other words, the programmer defines the bottom of the stack and the stack
grows up into reducing address range.

In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
• LXI SP, FFFFH
• This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
• The Size of the stack is limited only by the available memory
– Information is saved on the stack by PUSHing it on.
– It is retrieved from the stack by POPing it off.
• The 8085 provides two instructions: PUSH and POP for storing information
on the stack and retrieving it back.
– Both PUSH and POP work with register pairs ONLY.
The PUSH Instruction
PUSH B (1 Byte Instruction)
– Decrement SP
– Copy the contents of register B to the memory location pointed to by SP
– Decrement SP
– Copy the contents of register C to the memory location pointed to by SP

The POP Instruction


POP D (1 Byte Instruction)
– Copy the contents of the memory location pointed to by the SP to register E
– Increment SP
– Copy the contents of the memory location pointed to by the SP to register D
– Increment SP

PUSH PSW Register Pair


What is PSW (Program Status Word)?
– This register pair is made up of the Accumulator and the Flags registers.
PUSH PSW (1 Byte Instruction)
– Decrement SP
– Copy the contents of register A to the memory location pointed to by SP
– Decrement SP
– Copy the contents of Flag register to the memory location pointed to by SP

POP PSW (1 Byte Instruction)


– Copy the contents of the memory location pointed to by the SP to Flag
register
– Increment SP
– Copy the contents of the memory location pointed to by the SP to register A
– Increment SP
SUBROUTINE
A subroutine is a group of instructions (subprogram) that will be used
repeatedly in different locations of the program.
– Rather than repeat the same instructions several times, they can be grouped
into a subroutine that is called from the different locations.
– In Assembly language, a subroutine can exist anywhere in the code.
– However, it is customary to place subroutines separately from the main
program.
The 8085 has two instructions for dealing with subroutines.
– The CALL instruction is used to redirect program execution to the subroutine.
– The RET instruction is used to return the execution to the calling routine.
The CALL Instruction
CALL 4000H (3 byte instruction)
– When CALL instruction is fetched, the Microprocessor knows that the next
two Memory locations contain 16-bit subroutine address in the memory.

Microprocessor reads the subroutine address from the next two memory
location and stores the higher order 8bit of the address in the W register and
stores the lower order 8bit of the address
in the Z register
– Pushes the current value of Program Counter onto the stack [Return address]
– Loads the program counter with the 16‐bit address supplied with the CALL
instruction from WZ register.
RET (1 byte instruction)
– Retrieve the return address from the top of the stack
– Load the program counter with the return address.
Conditional CALL and RET Instructions:
The conditional call and the return instructions are based on four data conditions
(flags)-carry, zero, sign and parity.
The conditions are tested by checking the respective flags.
In case of a conditional call instruction, the program is transferred to the
subroutine if condition is met; otherwise, the main program is continued.
In case of a conditional return instruction, the sequence returns to the main
program if the condition is met; otherwise, the sequence in the subroutine is
continued.

The 8085 supports conditional CALL and conditional RET instructions.


Conditional CALL:
– CC, calls subroutine if Carry flag is set.
– CNC, call subroutine if Carry flag is not set
– CZ, calls subroutine if zero flag is set.
– CNZ, call subroutine if zero flag is not set
– CM, calls subroutine if sign flag is set. (sign=1 negative number)
– CP, call subroutine if sign flag is not set (sign =0 positive number)
Conditional Return:
– RC, returns from subroutine if Carry flag is set
– RNC, returns from subroutine if Carry flag is not set. Etc
– RZ, returns subroutine if zero flag is set.
– RNZ, returns subroutine if zero flag is not set
– RM, returns subroutine if sign flag is set. (Sign=1 negative number)
– RP, returns subroutine if sign flag is not set. (sign =0 positive number)
–RPE, returns subroutine if parity flag is set. (P=1 even parity)
–RPO, returns subroutine if parity flag is not set. (P=0 odd parity)

You might also like