Anda di halaman 1dari 7

LXI H,F000 // Load address to HL pair containing N=8

MOV A,M // Put N in accumulator

RAR // To find half of the total numbers

MOV C,A // Put accumulator content in the C register

INX H // Increment HL

BACK: MOV A,M

INX H // Increment HL pair

CMP M // Compare accumulator content with the content in //memory

JC SKIP // Jump to SKIP if Carry Flag is SET

MOV B,M // Put memory content pointed out by HL pair in B //register

MOV M,A // Put accumulator content in memory location //pointed by HL


register pair

DCX H // Decrement HL pair

MOV M,B // Put content of register B in memory location //pointed by HL


register pair

INX H // Increment HL pair

SKIP: INX H // Increment HL pair

DCR C // Decrement C register

JNZ BACK // Jump to Back Loop as long as ZERO flag is not //set

LXI SP,D000

LXI H,C000

PUSH H

LXI H,F001 // Initialize HL pair as pointer to first pair of data

LXI D,F003 //Initialize DE pair as pointer to second pa


MVI B,02

MVI C,02

MERGE: MOV A,M // Move memory location content to accumulator

XCHG // Exchange HL DE

CMP M // Com

JNC BIG // Jump to BIG if Carry flag in not SET

XTHL // Exchange HL SP

MOV M,A // Move accumulator content to memory

INX H // Increment HL pair

XTHL // Exchange HL SP

INX D // Increment DE pair

XCHG // Exchange HL DE

DCR B // Decrement counter B

JNZ MERGE // Jump to Merge if Carry Flag not SET

XCHG // Exchange HL DE

LOOP_B: MOV B,M // I

XTHL // Exchange HL SP

MOV M,B // Move content of B register to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL pair

DCR C // Decrement C register which is acting as a counter

JNZ LOOP_B // Jump to LOOP_B if ZERO flag NOT SET

JMP BACK1// Return to main program

BIG: MOV A,M


XTHL // Exchange HL SP

MOV M,A // Move accumulator content to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

XCHG // Exchange HL DE

DCR C // Decrement C register

JNZ MERGE // Jump to Merge if ZERO flag NOT SET

LOOP_A: MOV C,M // Move memory content to C register

XTHL // Exchange HL SP

MOV M,C // Move content of C register to memory location

INX H // Increment HL Pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

DCR B // Decrement B register

JNZ LOOP_A

JMP BACK1

BACK1: LXI SP,D000

LXI H,C004

PUSH H

LXI H,F005 // Initialize HL pair as pointer to third pair of data

LXI D,F007 // Initialize DE pair as pointer to fourth pair of //data

MVI B,02 // B register will act as counter


MVI C,02 // C register will act as counter

MERGE1: MOV A,M // Move memory location content to accumulator

XCHG // Exchange HL DE

CMP M // Com

JNC BIG1 // Jump to BIG if Carry flag in not SET

XTHL // Exchange HL SP

MOV M,A // Move accumulator content to memory

INX H // Increment HL pair

XTHL // Exchange HL SP

INX D // Increment DE pair

XCHG // Exchange HL DE

DCR B // Decrement counter B

JNZ MERGE1 // Jump to Merge if Carry Flag not SET

XCHG // Exchange HL DE

LOOP_B1: MOV B,M // I

XTHL // Exchange HL SP

MOV M,B // Move content of B register to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL pair

DCR C // Decrement C register which is acting as a counter

JNZ LOOP_B1 // Jump to LOOP_B if ZERO flag NOT SET

JMP BACK2 // Return to main program

BIG1: MOV A,M

XTHL // Exchange HL SP
MOV M,A // Move accumulator content to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

XCHG // Exchange HL DE

DCR C // Decrement C register

JNZ MERGE1 // Jump to Merge if ZERO flag NOT SET

LOOP_A1: MOV C,M // Move memory content to C register

XTHL // Exchange HL SP

MOV M,C // Move content of C register to memory location

INX H // Increment HL Pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

DCR B // Decrement B register

JNZ LOOP_A1

JMP BACK2

BACK2: LXI SP,D000

LXI H,F001

PUSH H

LXI H,C000// Initialize HL pair as pointer to one-half of //already sorted data


stack

LXI D,C004 // Initialize DE pair as pointer to second-ha

MVI B,04

MVI C,04 // C register will also act as counter


MERGE2: MOV A,M // Move memory location content to accumulator

XCHG // Exchange HL DE

CMP M // Com

JNC BIG2 // Jump to BIG if Carry flag in not SET

XTHL // Exchange HL SP

MOV M,A // Move accumulator content to memory

INX H // Increment HL pair

XTHL // Exchange HL SP

INX D // Increment DE pair

XCHG // Exchange HL DE

DCR B // Decrement counter B

JNZ MERGE2 // Jump to Merge if Carry Flag not SET

XCHG // Exchange HL DE

LOOP_B2: MOV B,M // I

XTHL // Exchange HL SP

MOV M,B // Move content of B register to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL pair

DCR C // Decrement C register which is acting as a counter

JNZ LOOP_B2 // Jump to LOOP_B if ZERO flag

JMP EXIT

RET // Return to main program


BIG2: MOV A,M

XTHL // Exchange HL SP

MOV M,A // Move accumulator content to memory location

INX H // Increment HL pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

XCHG // Exchange HL DE

DCR C // Decrement C register

JNZ MERGE2 // Jump to Merge if ZERO flag NOT SET

LOOP_A2: MOV C,M // Move memory content to C register

XTHL // Exchange HL SP

MOV M,C // Move content of C register to memory location

INX H // Increment HL Pair

XTHL // Exchange HL SP

INX H // Increment HL Pair

DCR B // Decrement B register

JNZ LOOP_A2

JMP EXIT

EXIT: HLT

Anda mungkin juga menyukai