Question: Write an assembly language program to obtain the largest of the contents of memory location 2222H and 2223H and store the number to next memory location i.e. 2224H

Flow Chart

ALP to Obtain Largest of contents in Memory Location - Flowchart
ALP to Obtain Largest of contents in Memory Location – Flowchart

Algorithm

Step 1: Point HL register pair to memory location 2222H

Step 2: Load the data on memory location to accumulator

Step 3: Increment the HL register pair by one to point at memory location 2223H

Step 4: Load the data on memory location to register B

Step 5: Compare the content of accumulator with content of register B

Step 6: If no carry from Step 5: jump to Step 8: (i.e. A>B)

Step 7: Move the data in B to A (i.e. A<B)

Step 8: Increment the HL register pair by one to memory location 2224H

Step 9: Store content of Accumulator to memory location

Step 10: Terminate the program

Assembly language

Here is code for ALP to obtain largest of contents in memory location in 8085 Microprocessor.

Label Instruction Comments
LXI H, 2222H ; HL pair points to location 2222H
MOV A, M ; Loads accumulator with the content of memory location (2222H)
INX H ; HL pair now points to location 2223H, HL increased by one
MOV B, M ; Loads register B with the content of memory location (2223H)
CMP B ; Compares contents of B and A
JNC jump1: ; Jumps to jump1: if no carry ( i.e. A>B)
MOV A, B ; Moves data of B to A (i.e. A<B)
jump1: INX H ; HL pair points to next location
MOV M, A ; Stores content of Accumulator to memory location (2224H)
HLT ; Terminates the program