Beruflich Dokumente
Kultur Dokumente
BACK: MOV A,M // Put memory content pointed out by HL pair in //accumulator
MOV M,A // Put accumulator content in memory location //pointed by HL register pair
MOV M,B // Put content of register B in memory location //pointed by HL register pair
JNZ BACK // Jump to Back Loop as long as ZERO flag is not //set
LXI SP,D000
LXI H,C000
PUSH H
// Initialize Stack Pointer to empty address //which will act as temporary stack to store data
while rearrangement is going //on.
MVI B,02 // B register will act as a counter ; 02 because there //are two numbers in first
pair
LXI SP,D000
LXI H,C005
PUSH H
// Initialize Stack Pointer to empty address //which will act as temporary stack to store
data while rearrangement is going //on.
LXI SP,D000
LXI H,C009
PUSH H
LXI H,F001// Initialize HL pair as pointer to one-half of //already sorted data stack
LXI D,F005 // Initialize DE pair as pointer to second-half of //already sorted data stack
//Initialize Stack Pointer to the top of address //where initial data has been stored The data will
be overwritten with the //sorted data
MVI B,04 // B register will act as counter; 04 because we are //now dealing with set of 4
numbers
HLT
MERGE: MOV A,M // Move memory location content to accumulator
XCHG // Exchange HL DE
CMP M // Compare accumulator content with memory content. //As HL pair is now
pointing where DE was pointing earlier, hence two //different sets elements are being compared.
XTHL // Exchange HL SP
XTHL // Exchange HL SP
XCHG // Exchange HL DE
XCHG // Exchange HL DE
LOOP_B: MOV B,M // If all elements of first set are already moved and //exhausted, then we just
need to move all elements of other set to the stack //below the LOOP_B does this task of moving whats
left of other set to //the stack
XTHL // Exchange HL SP
XTHL // Exchange HL SP
XTHL // Exchange HL SP
MOV M,A // Move accumulator content to memory location
XTHL // Exchange HL SP
XCHG // Exchange HL DE
XTHL // Exchange HL SP
XTHL // Exchange HL SP