Assembly Language Programming Using 8085
Assembly Language Programming Using 8085
Table of Contents
1. Introduction to Microprocessors ........................................................... Error! Bookmark not defined.
Components of microprocessor: .................................................... Error! Bookmark not defined.
Summary: ......................................................................................... Error! Bookmark not defined.
Evolution of microprocessor .......................................................... Error! Bookmark not defined.
Advantages of Microprocessor: ..................................................... Error! Bookmark not defined.
Applications of Microprocessors: .................................................. Error! Bookmark not defined.
2. Microprocessor system with bus organization ...................................... Error! Bookmark not defined.
3. Microprocessor architecture and operation.......................................... Error! Bookmark not defined.
1. Microprocessor-Initiated Operations and 8085/8080A Bus OrganizationError! Bookmark
not defined.
2. Internal Data Operations and the 8085/8080A Registers ....... Error! Bookmark not defined.
3. Peripheral or Externally Initiated Operations: ......................... Error! Bookmark not defined.
4. 8085 Microprocessor and its operation................................................. Error! Bookmark not defined.
1. Functional Block Diagram and Pin Configuration
See Slides….
See Slides….
See Slides….
4. Addressing Modes
See Slides….
5. Interrupts
When microprocessor receives any interrupt signal from peripheral(s) which are requesting its services, it
stops its current execution and program control is transferred to a sub-routine by generating CALL signal
and after executing sub-routine by generating RET signal again program control is transferred to main
program from where it had stopped.
When microprocessor receives interrupt signals, it sends an acknowledgement (INTA) to the peripheral
which is requesting for its service.
Software Interrupts are those which are inserted in between the program which means these are
mnemonics of microprocessor. There are 8 software interrupts in 8085 microprocessor. They are – RST 0,
RST 1, RST 2, RST 3, RST 4, RST 5, RST 6, RST 7.
Vectored and Non-Vectored Interrupts:
Vectored Interrupts are those which have fixed vector address (starting address of sub-routine) and after
executing these, program control is transferred to that address.
For Software interrupts, vector addresses are given as below. Vector Addresses are calculated by the
formula 8 * TYPE
Non-Vectored Interrupts are those in which vector address is not predefined. The interrupting device gives
the address of sub-routine for these interrupts. INTR is the only non-vectored interrupt in 8085
microprocessor.
Maskable Interrupts are those which can be disabled or ignored by the microprocessor. These interrupts
can be disabled. INTR, RST 7.5, RST 6.5, RST 5.5 are maskable interrupts in 8085 microprocessor.
Non-Maskable Interrupts are those which cannot be disabled or ignored by microprocessor. TRAP is a
non-maskable interrupt. It is used in critical power failure conditions.
Priority of Interrupts:
When microprocessor receives multiple interrupt requests simultaneously, it will execute the interrupt
service request (ISR) according to the priority of the interrupts.
6. Flags
See Slides….
Branching instructions refer to the act of switching execution to a different instruction sequence as a
result of executing a branch instruction. The three types of branching instructions are:
(a) Unconditional Jump Instructions: Transfers the program sequence to the described
memory address.
(b) Conditional Jump Instructions: Transfers the program sequence to the described memory
address only if the condition in satisfied.
OPCODE OPERAND EXPLANATION EXAMPLE
2. Call Instructions – The call instruction transfers the program sequence to the memory address
given in the operand. Before transferring, the address of the next instruction after CALL is pushed
onto the stack. Call instructions are 2 types: Unconditional Call Instructions and Conditional Call
Instructions.
(a) Unconditional Call Instructions: It transfers the program sequence to the memory address given in
the operand.
(b)Conditional Call Instructions: Only if the condition is satisfied, the instructions execute.
3. Return Instructions – The return instruction transfers the program sequence from the subroutine to
the calling program. Jump instructions are 2 types: Unconditional Jump Instructions and Conditional Jump
Instructions.
(a) Unconditional Return Instruction: The program sequence is transferred unconditionally from the
subroutine to the calling program.
(b) Conditional Return Instruction: The program sequence is transferred unconditionally from the
subroutine to the calling program only is the condition is satisfied.
NOP - No Operation
Algorithm:
Step1: Start the microprocessor
Step2: Initialize the carry as Zero
Step3: Load the first 8-bit data into the accumulator
Step4: Copy the contents of accumulator into the register B
Step5: Load the second 8-bit data into the accumulator.
Step6: Add the 2 - 8-bit datas and check for carry.
Step7: Jump on if no carry
Step8: Increment carry if there is
Step9: Store the added request in accumulator
Step10: More the carry value to accumulator
Step11: Store the carry value in accumulator
Step12: Stop the program execution.
Algorithm:
SUBTRACTION OF TWO 8 BIT NUMBERS
Problem: Write 8085 assembly language program for subtracting 2 bit (8) numbers.
Algorithm –
6. Load 00 in a register C (for borrow)
7. Load two 8-bit number from memory into registers
8. Move one number to accumulator
9. Subtract the second number with accumulator
10. If borrow is not equal to 1, go to step 7
11. Increment register for borrow by 1
12. Store accumulator content in memory
13. Move content of register into accumulator
14. Store content of accumulator in other memory location
15. Stop
Program –
Algorithm:
Algorithm:
Step1: Start the microprocessor
Step2: Get the 1st 8 bit numbers
Step3: Move the 1st 8it number to register B
Step4: Get the 2nd 8 bit number
Step5: Move the 2nd 8 bit number to register C
Step6: Initialize the accumulator as zero
Step7: initialize the carry as zero
Step8: Add both register B value as accumulator
Step9: Jump on if no carry
Step10: Increment carry by 1 if there is
Step11: Decrement the 2nd value and repeat from step 8, till the 2nd value becomes zero.
Step12: Store the multiplied value in accumulator
Step13: Move the carry value to accumulator
Step14: Store the carry value in accumulator
Result: The assembly language program for multiplication of two 8-bit numbers was executed using 8085
assembler and micro processing kit.
Algorithm:
Problem: Write a program for multiplication of two 8-bit numbers by repeated addition method.
Problem: Write a program for division of two 8-bit numbers by repeated subtraction method.
Problem – Multiply two 8-bit numbers stored at address 2050 and 2051. Result is
stored at address 3050 and 3051. Starting address of program is taken as 2000.
Algorithm:
1. We are taking adding the number 43 seven (7) times in this example.
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair
to store the result.
Program:
Memory Address Mnemonics Comment
2000 LHLD 2050 H←2051, L←2050
2003 XCHG H↔D, L↔E
Memory Address Mnemonics Comment
2004 MOV C, D C←D
2005 MVI D 00 D←00
2007 LXI H 0000 H←00, L←00
200A DAD D HL←HL+DE
200B DCR C C←C-1
200C JNZ 200A If Zero Flag=0, goto 200A
200F SHLD 3050 H→3051, L→3050
2012 HLT
Explanation:
Registers used: A, H, L, C, D, E
Another approach:
We can do multiplication of two 8-bit numbers without using DAD and XCHG
command.
Program:
ADDRESS MNEMONICS COMMENT
2000 LXI H, 2050H
2003 MOV B, M B←M
2004 INX H
2005 MOV C, M C←M
2006 MVI A, 00H A←00
2008 TOP: ADD B A<-A+B
2009 DCR C C←C-1
200A JNZ TOP
200D INX H
200E MOV M, A M←A
200F HLT terminate the program
Explanation: Registers A, H, L, C, B are used for general purpose.
1. LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
2. MOV B, M copies the content of memory into register B.
Algorithm:
1. Start the program by loading the HL pair registers with address of memory location.
2. Move the data to B Register.
3. Load the second data into accumulator.
4. Compare the two numbers to check carry.
5. Subtract two numbers.
6. Increment the value of carry.
7. Check whether the repeated subtraction is over.
8. Then store the results(quotient and remainder) in given memory location.
9. Terminate the program.
Program:
ADDRESS MNEMONICS COMMENT
2000 LXI H, 2050
2003 MOV B, M B<-M
2004 MVI C, 00 C<-00H
2006 INX H
2007 MOV A, M A<-M
2008 CMP B
2009 JC 2011 check for carry
200C SUB B A<-A-B
200D INR C C<-C+1
200E JMP 2008
2011 STA 3050 3050<-A
2014 MOV A, C A<-C
2015 STA 3051 3051<-A
2018 HLT terminate the program
MVI C, 00H
LXI H, 2021H
MOV A, M
MOV D, A
DCX H
MOV B, M
L2: MOV A, B
SUB D
JC L1
MOV B, A
INR C
JMP L2
L1: MOV L, C
MOV H, B
SHLD 2040H
HLT
11. Simple Sequence Programs, Branching, Looping
Problem: Sixteen data are stored in memory location at 2050H to 205FH. Transfer the entire block of data
to new location starting at 2070H.
Memory Address Content
2050 45
LXI H, 2050H 2051 23
MVI C, 10H 2052
LXI D, 2070H 2053
2054
L1: MOV A, M 2055
STAX D ; Transfer to new location 2070, … 2056
2057
INX H ; Increment first data address 2058
INX D ; Increment 2nd data address 2059
DCR C 205A
205B
JNZ L1 205C
HLT 205D
205E
205F
Problem: Add two numbers located at 2030H and 2040H. Store sum on 2050H. If carry is generated,
display it on 2051.
LDA 2030H
MOV B, A
LDA 2040H
ADD B
STA 2050H
JNC L1
MVI A, 01H
OUT 2051H
L1: HLT
Problem 05: Six bytes are stored in memory locations starting at 2050H. Add all the data bytes, save any
carry generated while adding the data bytes. Store total carry in 2070H and sum in 2071H.
LXI H, 2050H
MVI C, 06H
MVI B, 00H
MVI D, 00H
L2: MOV A, M
ADD B
MOV B, A
JNC L1
INR D
L1: INX H
DCR C
JNZ L2
HLT
Algorithm:
DESCENDING ORDER
Problem: To write a program to sort given n numbers in descending order
Algorithm:
SUM OF DATAS
Problem: To write an assembly language program to calculate the sum of datas using 8085 microprocessor
kit.
Algorithm:
Problem: Write a program for 8085 to find the smallest number among ten numbers stored from at
memory location 2500H.
LXI H, 2500H
MVI C, 0AH
MOV A, M
L2: INX H
CMP M
JC L1
MOV B, A ; If value is bigger, swap the accumulator with memory
MOV A, M ; If value is bigger, swap the accumulator with memory
MOV M, B ; If value is bigger, swap the accumulator with memory
L1: DCR C
JNZ L2
OUT PORT 1
HLT
TABLE PROCESSING
Problem: For ten bytes data starting from 1120H, write a program to sort the reading in ascending and in
descending order. (Note: For descending, do self)
Problem: There are two tables T1, T2 in memory having ten eight-bit data in each. Write a program for
8085 to find the difference of the corresponding element of these two tables. Store the result of each
operation on the corresponding element of the third table. Remember that the result should not be
negative; it should be |T1 – T2|.
Calculating BCD Equivalent. Convert each digit into groups of four binary digits equivalent.
Problem: Write an assembly language program for converting a 2-digit BCD number to its binary
equivalent using 8085 microprocessor.
Examples:
Input: 72H (0111 0010)2
Output: 48H (in hexadecimal) (0011 0000)2
((4x16)+(8x1))=72
Algorithm:
1. Load the BCD number in the accumulator
2. Unpack the 2-digit BCD number into two separate digits. Let the left digit be BCD1 and the right
one BCD2
3. Multiply BCD1 by 10 and add BCD2 to it
If the 2-digit BCD number is 72, then its binary equivalent will be 7 x OAH + 2 = 46H + 2 = 48H
Steps:
1. Load the BCD number from the memory location (201FH, arbitrary choice) into the accumulator
2. Temporarily store the accumulator’s value in B
3. Obtain BCD2 by ANDing the accumulator with 0FH and store it in C
4. Restore the original value of the accumulator by moving the value in B to A. AND the accumulator
with F0H
5. If the value in the accumulator equals 0, then BCD2 is the final answer and store it in the memory
location, 2020H (arbitrary)
6. Else, shift the accumulator to right 4 times to obtain BCD1. Next step is to multiply BCD1 by 0AH
7. Multiplication: Move BCD1 to D and initialise E with 0AH as the counter. Clear the accumulator to
0 and add D to it E number of times
8. Finally, add C to the accumulator and store the result in 2020H
2020H contains the result.
LABEL MNEMONIC
LDA 201FH
MOV B, A
ANI 0FH
MOV C, A
MOV A, B
ANI F0H
JZ SKIPMULTIPLY
RRC
RRC
RRC
RRC
MOV D, A
XRA A
MVI E, 0AH
SUM: ADD D
DCR E
JNZ SUM
SKIPMULTIPLY: ADD C
STA 2020H
HLT
Problem: WAP to read BCD number stored at memory location 2020H and converts it into binary
equivalent and finally stores that binary pattern into memory location 2030H. [Note: BCD number is the
combination from 0 to 9]
MVI C, 0AH
LXI H, 2020H
MOV A, M
ANI F0H
RRC
RRC
RRC
RRC
MOV B, A
MOV A, 00H
L1: ADD B
DCR C
JNZ L1
MOV D, A
MOV A, M
ANI 0FH
ADD D
STA 2030H
HLT
LXI H, 2050H
MVI C, 10H
L1: MVI M, FFH
INX H
DCR C
JNZ L1
HLT