PhysicsTeacher.in

High School Physics + more

Square of a number using a look-up table (assembly language program)

Problem statement: Write down an assembly language program to find the square of the numbers stored as an array starting at memory location C100H. Store the result as an array starting at memory location C200H. Assume that there are five numbers in the array.

Solution:

how to solve

The following program uses the look-up table concept. Instead of finding the squares by arithmetic operations, the calculated values of squares of 0 to 9 are stored in memory locations.

These memory locations are accessed using their addresses, the last digits of which are from zero to nine.

The program given in the table uses three register pairs and the indirect addressing mode for data transfer.

Look-up table for squares of numbers 0 to 9

The look-up table for squares of numbers 0 to 9 is given below:

Memory Address(H)Decimal numberSquare(H)
C300000
C301101
C302204
C303309
C304410
C305519
C306624
C307731
C308840
C309951
Look-up table for squares of numbers 0 to 9:

Input Data:

Memory Address(H)Data(H)
C10002
C10105
C10207
C10301
C10409

PROGRAM

Memory Address(H)Machine Code(H)LabelMnemonics(Instruction)Comments
C000 C001 C00221 00 C3
LXI H C300HLoad the register pair H-L with the address C300H; Initialize the look-up table pointer
C003 C004 C00511 00 C1
LXI D C100HInitialize the source memory array pointer
C006 C007 C00801 00 C2
LXI B C200HInitialize the destination memory array pointer
C0091ALOOPLDAX DGet a number from the source array.
C00A6F
MOV L, AMove the number to register L.
C00B7E
MOV A, MLoad the square in the accumulator.
C00C02
STAX BStore the result in the destination memory location.
C00D13
INX DIncrement the source memory pointer.
C00E03
INX BIncrement the destination memory pointer.
C00F7B
MOV A, EMove the lower-order byte of the source memory location to the accumulator.
C010 C011FE 05
CPI 05HCompare it with 05H
C012 C013 C014C2 09 C0
JNZ LOOPIf it is not equal to 05H, repeat the process.
C01576
HLTIf it is equal to 05H, terminate program execution.
square of a number using look-up table (assembly language program)

RESULT

Memory Address(H)Data(H)
C20004
C20119
C20231
C20301
C20451

See also  BCD to HEX Conversion program in 8085 - PhysicsTeacher.in
Scroll to top
error: physicsTeacher.in