Problem – Write an assembly language program in 8085 microprocessor to find square of 8 bit number.
Assumption – Addresses of input data and out data are 2050 and 3050 respectively.
Approach – Combine the content of registers H and L, the resultant content can be used to indirectly point to memory location and that memory location is specified by M. To find square of any number, keep on adding that number in accumulator A which initially contains 0 by that number of times whose square we need to find.
- Assign 20 to register H, 50 to register L and 00 to accumulator A
- Load the content of memory location which is specified by M in register B
- Add content of M in accumulator A and decrement value of B by 01
- Check if B holds 00, if true then store the value of A at memory location 3050 otherwise go to step 3
|2000||MVI H 20||H <- 20|
|2002||MVI L 50||L <- 50|
|2004||MVI A 00||A <- 00|
|2006||MOV B, M||B <- M|
|2007||ADD M||A <- A + M|
|2008||DCR B||B <- B – 01|
|2009||JNZ 2007||Jump if ZF = 0|
|200C||STA 3050||M <- A|
Explanation – Registers used A, H, L, B and indirect memory M:
- MVI H 20 – initialize register H with 20
- MVI L 50 – initialize register L with 50
- MVI A 00 – initialize accumulator A with 00
- MOV B, M – moves the content of memory location which is indirectly specified by M in register B
- ADD M – add the content of memory location which is indirectly specified by M in accumulator A
- DCR B – decrement value of register B by 1
- JNZ 2007 – jump to memory location 2007 if ZF = 0, i.e register B does not contain 0
- STA 3050 – stores value of A in 3050
- HLT – stops executing the program and halts any further execution
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to find sum of digits of 8 bit number
- 8085 program to find minimum value of digit in the 8 bit number
- 8085 program to convert an 8 bit number into Grey number
- 8085 program to count number of ones in the given 8-bit number
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to find square root of a number
- 8085 program to find maximum of two 8 bit numbers
- 8085 program to find larger of two 8 bit numbers
- 8085 program to find the set bit of accumulator
- 8085 program to convert 8 bit BCD number into ASCII Code
- 8085 program to reverse 16 bit number
- 8085 program to reverse 8 bit number
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to show masking of lower and higher nibbles of 8 bit number
- 8085 program to perform AND operation in nibbles of 8 bit number
- 8085 program to check whether both the nibbles of 8 bit number are equal or not
- 8085 program to add two 8 bit numbers
- 8085 program to multiply two 8 bit numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.