- 2073 Magh · 8 marks
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)
Related questions
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- 8085 ALP: count ones in upper nibble · Microprocessor, chapter 2
- 8085 ALP: multiplication table of a number · Microprocessor, chapter 2
- 8085 ALP: divide two bytes · Microprocessor, chapter 2
- 8085 ALP: add upper and lower nibbles · Microprocessor, chapter 2
- 8085 ALP: odd parity transfer with bit change · Microprocessor, chapter 2
- C program: sum of two 8-bit BCD numbers · Embedded System, chapter 9
- Protected specifier; student/test/result program · Object Oriented Programming, chapter 6
- Greatest and smallest of ten numbers · Computer Programming, chapter 11
- Short note: Stored program control · Telecommunications, chapter 4