Skip to main content

8085 ALP: square of ten numbers

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.

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.

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.

        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).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →