Programming in 8085Let's see some simple example to demonstrate the use of some important instructions of 8085. The memory addresses given in the program are for a particular microprocessor kit. These addresses can be changed to suit the microprocessor kit available in your system. Store 8-bit data in memoryProgram Store 8-bit data in memory using direct addressing Store 8-bit data in memory using indirect addressing Add two 8-bit numbersExample (2501 H) = 99H (2502 H) = 39H Result (2503 H) = 99H + 39H = D2H Since, 1 0 0 1 1 0 0 1 (99H) + 0 0 1 1 1 0 0 1 (39H) 1 1 0 1 0 0 1 0 (D2H) Program Subtract two 8-bit numbersExample (2501 H) = 49H (2502 H) = 32H Result (2503 H) = 49H - 32H = 17H Program Add two 16-bits numbersAdd the 16-bit number in memory locations 2501H and 2502H to the 16-bit number in memory locations 2503H and 2504H. The most significant eight bits of the two numbers to be added are in memory locations 2502H and 4004H. Store the result in memory locations 2505H and 2506H with the most significant byte in memory location 2506H. Example (2501H) = 15H (2502H) = 1CH (2503H) = B7H (2504H) = 5AH Result = 1C15 + 5AB7H = 76CCH (2505H) = CCH (2506H) = 76H Program Add two 16-bits number with ADD and ADC instruction Add two 16-bits numbers with DAD instruction Subtract two 16-bit numbersExample (2500H) = 19H (2501H) = 6AH (2504H) = 15H (2503H) = 5CH Result = 6A19H ? 5C15H = OE04H (2504H) = 04H (2505H) = OEH Program Add contents of two memory locationsExample (2500H) = 7FH (2501H) = 89H Result = 7FH + 89H = lO8H (2502H) = 08H (2503H) = 01H Program Finding 1's complement of a numberTo obtain one's complement of a number its 0 bits are replaced by 1 and 1 by 0. Example 1 (2501H) = 96 H = 1001 0110 (9) (6) One's complement = 0110 1001 = 69 H Result = (2502H) = 69H Example 2 (2501H) = E4H Result = (2502H) = 1BH Program The number is placed in the memory location 2501 H. The result is stored in the memory location 2502 H. Finding 2's complement of a number2's complement of a number is obtained by adding 1 to the 1's complement of the number. Example To find the two's complement of 96. 96 = 1001 0110 1's complement = 0110 1001 = 69 + 0000 0001 2's complement = 0110 1010 = 6A Program The number is placed in the memory location 2501 H. The result is to be stored in the memory location 2502 H. Count number of 1's in a numberExample 2501 H = 04 2502 H = 34 H 2503 H = A9H 2504 H = 78H 2505 H = 56H Result = 2503 H = A9H Program Count number of 1's of the content of the register D and store the count in the register B. Find larger of two numbersExample 2501H = 98 H 2502H = 87H Result = 98H (2503H) Program The first number 98H is placed in the memory location 2501 H. LXI H, 2501H : "Address of first number in H-L pair" MOV A, M : "1stt number in accumulator" INX H : "Address of 2nd number in H-L pair" CMP M : "compare 2nd number with 1st number" JNC AHEAD : "No, larger is in accumulator. Go to AHEAD" MOV A, M : "Yes, get 2nd number in the accumulator" STA 2503 H : "Store larger number in 2503H" HLT : "Stop" Find smaller of two numbersExample 2501H = 84 H 2502H = 99 H Result = 84 H(2503H) Program The first number 84H is placed in the memory location 2501 H. The second number 99H is placed in the memory location 2502H. The result is stored in the memory location 2503 H. LXI H, 2501H : "Address of first number in H-L pair" MOV A, M : "1stt number in accumulator" INX H : "Address of 2nd number in H-L pair" CMP M : "compare 2nd number with 1st number" JC AHEAD : "Yes, smaller number is in accumulator. Go to AHEAD" MOV A, M : "No, get 2nd number in the accumulator" STA 2503 H : "Store smaller number in 2503H" HLT : "Stop" Calculate the sum of series of even numbersExample 2500 H = 4H 2501 H = 20H 2502 H = 15H 2503 H = 13H 2504 H = 22H Result = 2505 H = 20+22= 42H Program The numbers are placed in the memory locations 2501 to 2504H. The sum is to be stored in the memory location 2450H. As there are 4 numbers in the series, count = 04 The initial value of the sum is made 00. The even number of the series are taken one by one and added to the sum. Calculate the sum of series of odd numbersExample 2500 H = 4H 2501 H = 9AH 2502 H = 52H 2503 H = 89H 2504 H = 3FH Result = 2505 H = 89H + 3FH= C8H Program The numbers are placed in the memory locations 2501 to 2504H. The sum is to be stored in the memory location 2450H. As there are 4 numbers in the series, count = 04 The initial value of the sum is made 00. The odd number of the series are taken one by one and added to the sum. Find the square of given numberProgram Find the square of 07 (decimal) using lookup table techniques. The number 07 D is in the memory. The result is to be stored in the memory location 2501H. The table for square is stored from 2600 to 2609 H. Separate even numbers from given numbersProgram Let's see the program to separate even numbers from the given list of 50 numbers and store them in other location starting from 2600H. Starting location of 50 number list is 2500H. Next TopicMicroprocessor Applications |