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 (contains flowchart)

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

Flowchart for Assembly language program to find largest number among two

Flowchart for Assembly language program to find largest number among two

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

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

 

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>