---
title: "8085 ALP: square of ten numbers"
subject: "Microprocessor"
chapter: 2
key: "semester_4/microprocessor:alp-8085-square-numbers"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-square-numbers
site: BCT Engineering
---

# 8085 ALP: square of ten numbers

Microprocessor · Chapter 2: Programming with 8085 Microprocessor

- Asked in: 2073 Magh, 8 marks
- Video: [Program to find square of a number using lookup table in 8085|Look up table in 8085|ALP in 8085](https://www.youtube.com/watch?v=si_i-MRmY-M) — Scratch Learners
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-square-numbers
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-2

## Question

Write an assembly language program for 8085 to find the square of ten 8-bit numbers which are ≤ 0FH, stored from memory location C090H. Store the result from the end of the source table.

## Short answer

Square of each 8-bit number n ≤ 0FH is computed by adding n to accumulator n times (zero yields 0). Ten numbers from C090H are processed, results (max E1H) stored from C09AH onward.

## Answer

**Assumptions:** the ten numbers are at C090H to C099H. The squares (maximum 0FH x 0FH = E1H, fits in 8 bits) are stored from C09AH, the location just after the source table.

**Method:** the square of n is found by adding n to the accumulator n times. A zero is checked first so that the loop does not run 256 times.


```asm
        LXI H,0C090H    ; HL -> source table
        MVI C,0AH       ; 10 numbers
LOOP:   MOV B,M         ; B = n
        MOV D,B         ; D = repeat count
        XRA A           ; A = 0 (square so far)
        INR D
        DCR D           ; test D for zero
        JZ STORE        ; n = 0 -> square is 0
ADDLP:  ADD B           ; add n, n times
        DCR D
        JNZ ADDLP       ; A = n x n
STORE:  MOV E,A         ; E = square
        MOV A,L
        ADI 0AH         ; L + 10 -> result location (C09AH + i)
        MOV L,A
        MOV M,E         ; store the square
        SUI 09H         ; A = L(old) + 1
        MOV L,A         ; HL -> next number
        DCR C
        JNZ LOOP
        HLT
```


**Example:** n = 0DH gives 13 additions of 0DH = A9H (169).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How does the program compute n squared?
   A. Using the MUL instruction on B
   B. By shifting n left n times with RAL
   C. By clearing A and adding n to it n times, with D as the counter
   D. By adding n to itself once (A = n + n)
   Answer: C. The 8085 has no multiply instruction, so A is cleared with XRA A and B (= n) is added n times, with D counting down from n. (Key point: Square by repeated addition: add n to A, n times)

2. Why does the program check D for zero (INR D, DCR D, JZ STORE) before the addition loop?
   A. If n = 0, DCR D would wrap from 00H to FFH, so the addition loop would run 256 times needlessly
   B. To clear the carry flag before ADD
   C. Because DCR does not affect the zero flag
   D. To stop the program when the end of the table is reached
   Answer: A. With D = 0, DCR D would wrap to FFH and the loop would run 256 times (adding 0 each time, so the result is still 0 but the work is wasted). Testing D first sends n = 0 straight to STORE with A = 0. DCR does affect the zero flag, which is why INR D / DCR D can be used as the test. (Key point: Zero check prevents the loop running 256 times)

3. Why can each square be stored in a single byte, and where is the result for the number at C093H stored?
   A. Because 0FH x 0FH = FFH; at C094H
   B. Because 0FH x 0FH = E1H (225) fits in 8 bits; at C09DH (C093H + 0AH)
   C. Because only the low byte is kept; at C09AH
   D. Because 0FH x 0FH = 1E1H, but the carry is ignored; at C09DH
   Answer: B. The largest number is 0FH and 0FH x 0FH = E1H, which fits in 8 bits. Results start at C09AH, just after the 10-byte table, so each result is at its source address + 0AH. (Key point: Max square E1H fits in 8 bits; result stored at source address + 0AH)

## Related in Microprocessor

- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [8085 ALP: count ones in upper nibble](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-upper-nibble) — Microprocessor, chapter 2
- [8085 ALP: multiplication table of a number](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-multiplication-table) — Microprocessor, chapter 2
- [8085 ALP: divide two bytes](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-divide-bytes) — Microprocessor, chapter 2
- [8085 ALP: add upper and lower nibbles](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-add-nibbles) — Microprocessor, chapter 2
- [8085 ALP: odd parity transfer with bit change](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-odd-parity-transfer) — Microprocessor, chapter 2

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
- [Greatest and smallest of ten numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-greatest-smallest-ten) — Computer Programming, chapter 11
- [Short note: Stored program control](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Ashort-note-spc-digital-exchange) — Telecommunications, chapter 4
