Programs For 8085 Microprocessor Level 2
Count number of one’s in a number
Statement:
Write a program to count number of l’s in the contents of D register and store the count in the B register.
Sample problem (2200H) = 04 (2201H) = 34H (2202H) = A9H (2203H) = 78H (2204H) = 56H Result = (2202H) = A9H
MVI B, 00H MVI C, 08H MOV A, D BACK: RAR JNC SKIP INR B SKIP: DCR C JNZ BACK HLT
Arrange in ascending order
Statement:
Write a program to sort given 10 numbers from memory location 2200H in the ascending order.
MVI B, 09 :"Initialize counter" START :"LXI H, 2200H: Initialize memory pointer" MVI C, 09H :"Initialize counter 2" BACK: MOV A, M :"Get the number" INX H :"Increment memory pointer" CMP M :"Compare number with next number" JC SKIP :"If less, don’t interchange" JZ SKIP :"If equal, don’t interchange" MOV D, M MOV M, A DCX H MOV M, D INX H :"Interchange two numbers" SKIP:DCR C :"Decrement counter 2" JNZ BACK :"If not zero, repeat" DCR B :"Decrement counter 1" JNZ START HLT :"Terminate program execution"
Calculate the sum of series of even numbers
Statement:
Calculate the sum of series of even numbers from the list of numbers. The length of the list is in memory location 2200H and the series itself begins from memory location 2201H. Assume the sum to be 8 bit number so you can ignore carries and store the sum at memory location 2210H.
Sample problem 2200H= 4H 2201H= 20H 2202H= l5H 2203H= l3H 2204H= 22H Result 22l0H= 20 + 22 = 42H = 42H
LDA 2200H MOV C, A :"Initialize counter" MVI B, 00H :"sum = 0" LXI H, 2201H :"Initialize pointer" BACK: MOV A, M :"Get the number" ANI 0lH :"Mask Bit l to Bit7" JNZ SKIP :"Don’t add if number is ODD" MOV A, B :"Get the sum" ADD M :"SUM = SUM + data" MOV B, A :"Store result in B register" SKIP: INX H :"increment pointer" DCR C :"Decrement counter" JNZ BACK :"if counter 0 repeat" STA 2210H :"store sum" HLT :"Terminate program execution"
Calculate the sum of series of odd numbers
Statement:
Calculate the sum of series of odd numbers from the list of numbers. The length of the list is in memory location 2200H and the series itself begins from memory location 2201H. Assume the sum to be 16-bit. Store the sum at memory locations 2300H and 2301H.
Sample problem 2200H = 4H 2201H= 9AH 2202H= 52H 2203H= 89H 2204H= 3FH Result = 89H + 3FH = C8H 2300H= H Lower byte 2301H = H Higher byte
Source program : LDA 2200H MOV C, A :"Initialize counter" LXI H, 2201H :"Initialize pointer" MVI E, 00 :"Sum low = 0" MOV D, E :"Sum high = 0" BACK: MOV A, M :"Get the number" ANI 0lH :"Mask Bit 1 to Bit7" JZ SKIP :"Don’t add if number is even" MOV A, E :"Get the lower byte of sum" ADD M :"Sum = sum + data" MOV E, A :"Store result in E register" JNC SKIP INR D :"Add carry to MSB of SUM" SKIP: INX H :"Increment pointer"
Find the square of given number
Statement:
Find the square of the given numbers from memory location 6100H and store the result from memory location 7000H.
Sample problem 2200H = 4H 2201H= 9AH 2202H= 52H 2203H= 89H 2204H= 3FH Result = 89H + 3FH = C8H 2300H= H Lower byte 2301H = H Higher byte
LXI H, 6200H :"Initialize lookup table pointer" LXI D, 6100H :"Initialize source memory pointer" LXI B, 7000H :"Initialize destination memory pointer" BACK: LDAX D :"Get the number" MOV L, A :"A point to the square" MOV A, M :"Get the square" STAX B :"Store the result at destination memory location" INX D :"Increment source memory pointer" INX B :"Increment destination memory pointer" MOV A, C CPI 05H :"Check for last number" JNZ BACK :"If not repeat" HLT :"Terminate program execution"
Search a byte in a given number
Statement:
Search the given byte in the list of 50 numbers stored in the consecutive memory locations and store the address of memory location in the memory locations 2200H and 2201H. Assume byte is in the C register and starting address of the list is 2000H. If byte is not found store 00 at 2200H and 2201H.
LX I H, 2000H :"Initialize memory pointer 52H" MVI B, 52H :"Initialize counter" BACK: MOV A, M :"Get the number" CMP C :"Compare with the given byte" JZ LAST :"Go last if match occurs" INX H :"Increment memory pointer" DCR B :"Decrement counter" JNZ B :"If not zero, repeat" LXI H, 0000H SHLD 2200H JMP END :"Store 00 at 2200H and 2201H" LAST: SHLD 2200H :"Store memory address" END: HLT :"Stop"
Add two decimal numbers of 6 digit each
Statement:
Two decimal numbers six digits each, are stored in BCD package form. Each number occupies a sequence of byte in the memory. The starting address of first number is 6000H Write an assembly language program that adds these two numbers and stores the sum in the same format starting from memory location 6200H.
LXI H, 6000H :"Initialize pointer l to first number" LXI D, 6l00H :"Initialize pointer2 to second number" LXI B, 6200H :"Initialize pointer3 to result" STC CMC :"Carry = 0" BACK: LDAX D :"Get the digit" ADD M :"Add two digits" DAA :"Adjust for decimal" STAX.B :"Store the result" INX H :"Increment pointer 1" INX D :"Increment pointer2" INX B :"Increment result pointer" MOV A, L CPI 06H :"Check for last digit" JNZ BACK :"If not last digit repeat" HLT :"Terminate program execution"
Separate even numbers from given numbers
Statement:
Write an assembly language program to separate even numbers from the given list of 50 numbers and store them in the another list starting from 2300H. Assume starting address of 50 number list is 2200H.
LXI H, 2200H :"Initialize memory pointer l" LXI D, 2300H :"Initialize memory pointer2" MVI C, 32H :"Initialize counter" BACK:MOV A, M :"Get the number" ANI 0lH :"Check for even number" JNZ SKIP :"If ODD, don’t store" MOV A, M :"Get the number" STAX D :"Store the number in result list" INX D :"Increment pointer 2" SKIP: INX H :"Increment pointer l" DCR C :"Decrement counter" JNZ BACK :"If not zero, repeat" HLT :"Stop
Transfer contents to overlapping memory blocks
Statement:
Write assembly language program with proper comments for the following:A block of data consisting of 256 bytes is stored in memory starting at 3000H. This block is to be shifted (relocated) in memory from 3050H onwards. Do not shift the block or part of the block anywhere else in the memory.
Two blocks (3000 – 30FF and 3050 – 314F) are overlapping. Therefore it is necessary to transfer last byte first and first byte last.
MVI C, FFH :"Initialize counter" LX I H, 30FFH :"Initialize source memory pointer 3l4FH" LXI D, 314FH :"Initialize destination memory pointer" BACK: MOV A, M :"Get byte from source memory block" STAX D :"Store byte in the destination memory block" DCX H :"Decrement source memory pointer" DCX :"Decrement destination memory pointer" DCR C :"Decrement counter" JNZ BACK :"If counter 0 repeat" HLT :"Stop execution"