In this program, we will see how to find the square of an 8-bit number.
Write 8085 Assembly language program to find the square of a number The number is stored at location 8000H, store the result at 8050H.
In 8085, we cannot perform the multiplication operation directly. We are performing the multiplication by using repetitive addition. To get square of a number, we have to multiply the number with itself.
Address | Data |
---|---|
… | … |
8000 | 0C |
… | … |
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | | LXI H,8000H | Load the number from 8000H |
F003 | AF | | XRA A | Clear accumulator |
F004 | 46 | | MOV B,M | Load data from memory to B |
F005 | 86 | LOOP | ADD M | Add memory byte with A |
F006 | 05 | | DCR B | Decrease B by 1 |
F007 | C2, 05, F0 | | JNZ LOOP | If Z = 0, jump to loop |
F00A | 32, 50, 80 | | STA 8050H | Store result into memory |
F00D | 76 | | HLT | Terminate the program |
Address | Data |
---|---|
… | … |
8050 | 90 |
… | … |