0% found this document useful (0 votes)
44 views

Lxi H, Add1 Mov C, M Inx H Mov A, M Add2: Inx H CMP M JNC Less Mov A, M Less: DCR C JNZ Add2 Sta Add - Output

This program sorts 10 numbers stored from memory location 2200H in ascending order using a bubble sort algorithm. It initializes a counter B to 09 to loop 10 times for each number. It then initializes the memory pointer H to 2200H and counter C to 09H for the inner loop comparisons. It compares each number to the next and interchanges them if out of order, decrementing the counters after each pass until sorting is complete.

Uploaded by

raghuramu23456
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Lxi H, Add1 Mov C, M Inx H Mov A, M Add2: Inx H CMP M JNC Less Mov A, M Less: DCR C JNZ Add2 Sta Add - Output

This program sorts 10 numbers stored from memory location 2200H in ascending order using a bubble sort algorithm. It initializes a counter B to 09 to loop 10 times for each number. It then initializes the memory pointer H to 2200H and counter C to 09H for the inner loop comparisons. It compares each number to the next and interchanges them if out of order, decrementing the counters after each pass until sorting is complete.

Uploaded by

raghuramu23456
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program to find the Maximum number from a given array LXI H, ADD1 MOV C , M INX H MOV A, M ADD2: INX

H CMP M JNC LESS MOV A,M LESS: DCR C JNZ ADD2 STA ADD_OUTPUT

LXI H,ADD1 ; Load 16 bit data in reg pair H MOV C,M ; Load the counter to compare the total no of data to count INX H ; Increment the address to point to the next location MOV A,M ; Load the second no in the accumulator ADD2: ; Label to jump at INX H ; Increment the address to point to the next location CMP M ; Compate the accumulator with the next no in series JNC LESS: ; Jmp to a location with the comparision returns a carry MOV A,M ; Move the content of the location M into the accumulator if the Jump fails LESS: ; Label to jump at DCR C ; decrement the counter JNZ ADD2 ; Jump if there is anything more to compare STA ADD_OUTPUT

; Accumulator will contain the Max no and move to the out put address. Program to sort n numbers by Bubble sort Statement:Write a program to sort given 10 numbers from memory location 2200H in the ascending order

Source program: MVI B, 09 : Initialize counter START : LXI H, 2200H: Initialize memory pointer MVI C, 09H : Initialize counter 2 BACK: MOV A, M : Get the number INX H : Increment memory pointer CMP M : Compare number with next number JC SKIP : If less, don't interchange JZ SKIP : If equal, don't interchange MOV D, M MOV M, A DCX H MOV M, D INX H : Interchange two numbers SKIP:DCR C : Decrement counter 2 JNZ BACK : If not zero, repeat DCR B : Decrement counter 1 JNZ START HLT : Terminate program execution Program to sort n numbers by selection sort

LXI H, 0060H MVI B, 05H LOOP1: MOV C, B MOV D, H MOV E, L INR E LOOP2: LDAX D CMP M JNC NO_SWP SWAP: MOV D, M MOV M, A MOV A, D MOV D, H STAX D NO_SWP: INR E DCR C JNZ LOOP2 INX H DCR B JNZ LOOP1 HLT

You might also like