Vous êtes sur la page 1sur 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

Vous aimerez peut-être aussi