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

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 of an assembly language program to find the largest among the three number

Flowchart of an assembly language program to find the largest among the three number

Algorithm

Step 1: Load Accumulator (A) with value1

Step 2: Load register B with value2

Step 3: Load register C 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 B to A (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

 

Assembly language

Label Instruction Comments
  MVI A, 06H ; Loads Accumulator with 06H
  MVI B, 0AH ; Loads register B 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

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>