Assembly Language Program Examples of 8085 Microprocesssor

In the previous article we have discussed about art of programming and different programming techniques of 8085 microprocessor like flow chart, modular programming, top down approach and structured programming. In this article we will discuss some assembly language program and how to write assembly language program (ALP).

What is Assembly Language Program

Machine language and Hex code instructions are very difficult for the programmer. Hence for programmer, the instructions of microprocessor are made in the form of English abbreviation (short form). These instructions are name as Assembly Language instructions or mnemonics. The combinations of different mnemonics are known as Assembly Language Program and it is a low level language.

Examples of assembly language program

Loading Register or Memory with Data

Example 1: Write a program to transfer 07 H in register L.

Memory AddressMachine CodeMnemonicsOperandsComments
2000 H2E, 07MVIL, 07Move immidiate 07 in register L
2002 H76HLTStop or terminate the program

The instruction MVI L, 07 will move the data 07 to the register L. The instruction will stop the program. The machine code for the instruction MVI L, 07 is 2E, 07. The 1st byte of the machine code is 2E which is the Hex code for the instruction MVI L. The second byte is the data 07. The machine code for HLT is 76. The machine codes are fetch in the memory locations, starting from the memory locations 2000 H. Memory location 2000 H contains 2E, 2001 H contains 07 and memory location 2002 H contain 76, After the execution of a program, the contents of Register L can be examined which are 07.

Example 2 Write a program to load register A with 08 H and then move it to register C.

Memory AddressMachine CodeMnemonicsOperandsComments
2000 H3E, 08MVIA,08Get 08 in register A
2002 H4FMOVC,AMove the contents of register A to regsiter C
2003 H76HLTHalt

In this program the instruction MVI A, ON H will place the given data 08 1H in the register A. The Hex code for MVI A, 08 H is 3E, 08 IH where 3E is the Hex code for MVI A. The instruction MOV C, A will move the contents of register A to the register C. Its machine code is 4F. With this instruction the data of register A is copies into the register C. It means the given data, is 08 H which was previously placed in register A is now copied into the register C.

The instruction HLT whose machine code is 76 stops the program. The memory locations required for this program are 2000 H to 2003 H. Any other memory locations can be selected. After the execution of a program, the contents of register C can be examined.

Example 3. Write a program to load the contents of memory location 2050 H into accumulator and then move this data into register B

Memory AddressMachine CodeMnemonicsOperandsComments
2000 H3A, 50, 20LDA2050 HLoad the contents of memory location 2050 H into the accumulator
2002 H47MOVB,AMove the contents of register A to regsiter B
2004 H76HLTStop

The instruction LDA 2050 H will load the contents of memory location 2050 H into the accumulator. The machine code for the instruction LDA is 3A. The instruction MOV B. A (Machine code 47) will move the contents of Accumulator to the register B. First of all data 07 is fetch in the memory location 2050. Then memory locations 2000 H contain 3A, 2001 H contain 50 H, 2002 H contains 20 H, 2003 H contains 47 H and 2004 H contains 76 H. After execution of a program, the contents of register B can be examined.

Example 4. The contents of memory location 2050 H are FF H. Move these contents to Register C.

Data: Suppose memory location 2050 H contains FF H

Memory AddressMachine CodeMnemonicsOperandsComments
2000 H3E, 08MVIA, 08 HMove immediate data of 08 H in the Accumulator
2002 H3CINRAIncrement the contents og accumulator by 1
2003 H32, 50, 20STA2050 HStore the contents of accumulator in memory location 2050 H.
2004 H76HLTStop

In this program, data is fetch in memory location 2050 H. This data is to fetch register C. The first instruction LXI H, 2050 H will load to the memory address 2050 H in the register pair H-L. The machine code for the instruction LXI H is 21. It should be fetch in the memory address 2000 H. For the memory address 2050 H, the second byte 50 H (lower address) is fetch in memory location 2001 H and the first byte of address 20 H (higher address) is fetch in memory location 2002 H. The instruction MOV C, M will move the contents of memory location whose address is in the H-L pair registers to the register C. It means the data FF H is copied in the register C from the memory address 2050 H. The register C can be examined which will contain data FF H.

Example 5 Transfer the contens of Memory location 2050 H to the register B and the contents of 2051 H to Register C. The contents of memory location 2050 H are 10 of 2051 H are 11.

Data: Suppose memory location 2050 H contains 10 and 2051 H contains 11.

Memory AddressMachine CodeMnemonicsOperandsComments
2000 H21, 01, 24LXIH, 2401 HPlace address of the 1st number in H-L register pair
2003 H7EMOVA, MMove contents of memory addressed by H-L pair of the accumulator
2004 H23INXHIncerese the contents of H-L pair by 1
2005 H86ADDMAdd the 2nd number in the first number, and the result is in accumulator.
2006 H32, 03, 24STAStore the result in the memory location 2403 H
2009 H76HLT2403 HStop

The instruction LXI H, 2050 H will place the memory address 2050 H in the register pair H-L The machine code for the instruction LXI H, 2050 H is 21, 50, 20ยท Then the instruction MOV B, M will copy the contents of memory location 2050 H whose address is in the H-L register pair to the register B. The machine code for the instruction MOV B. M is 46, The instruction INX H will increase the contents of register pair H-L by 1ie, after the instruction INX, the H-L register pair will contain the address 2051 H. The machine code for the instruction INX. H is 23.

The instruction MOV C. M will move the contents of memory location whose address is in the H-L register pair i.e., (contents of memory address 2051 H) to the register C. The machine code for the instruction MOV C, M is 4E. After the execution of a program, the contents of register B and of register C can be examined, which will contain 10 H and 11 H respectively.