Question: Write an assembly language program to find the largest of the three number 06H, 0AH and 0BH, and store the result in 4200H.

Flowchart

Flowchart for program to find the largest of three numbers.
Flowchart for program to find the largest of three numbers.

Algorithm

Step 1: Load Accumulator (A) with value1

Step 2: Load register with value2

Step 3: Load register with value3

Step 4: Compare B with A, gives carry if value2 is greater than value1 (i.e. B>A)

Step 5: When no carry from Step 4: go to Step 7:  (i.e. when A>B)

Step 6: Move content of register to (i.e. when B>A)

Step 7: Compare C with A, gives carry if value3 is greater than value1 (i.e. C>A)

Step 8: When no carry from Step 7: go to Step10: (i.e. when A>C)

Step 9: Move content of register C to A (i.e. when C>A)

Step 10: Store content of Accumulator to memory location 4200H

Step 11: Terminate the program

ALP to find largest of 3 numbers

Label Instruction Comments
MVI A, 06H ; Loads Accumulator with 06H
MVI B, 0AH ; Loads register with 0AH
MVI C, 0BH ; Loads register C with 0BH
CMP B ; Compares B with A
JNC jump1: ; On no carry jumps to jump1:
MOV A, B ; Moves content of B to A
jump1: CMP C ; Compares C with A
JNC jump2: ; On no carry jumps to jump2:
MOV A, C ; Moves content of C  to A
jump2: STA 4200H ; Stores content of A to memory location 4200H
HLT ; Terminates the program