Header Ads Widget

Ticker

6/recent/ticker-posts

Write an Assembly Language Program to arrange given numbers in ascending order

 Algorithm

1. Initialize HL pair as memory pointer
2. Get the count at 4200 into C - register
3. Copy it in D - register (for bubble sort (N-1) times required)
4. Get the first value in A - register
5. Compare it with the value at next location
6. If they are out of order, exchange the contents of A - register and Memory
7. Decrement D - register content by 1
8. Repeat steps 5 and 7 till the value in D- register become zero
9. Decrement C - register content by 1
10. Repeat steps 3 to 9 till the value in C - register becomes zero

LXI H,5000    ;Set pointer for array    
          MOV C,M       ;Load the Count
          DCR C         ;Decrement Count
  REPEAT: MOV D,C
          LXI H,5001
    LOOP: MOV A,M       ;copy content of memory location to Accumulator
          INX H
          CMP M
          JC SKIP       ;jump to skip if carry generated
          MOV B,M       ;copy content of memory location to B - Register
          MOV M,A       ;copy content of Accumulator to memory location
          DCX H         ;Decrement content of HL pair of registers
          MOV M,B       ;copy content of B - Register to memory location
          INX H         ;Increment content of HL pair of registers
    SKIP: DCR D         ;Decrement content of Register - D
          JNZ LOOP      ;jump to loop if not equal to zero
          DCR C         ;Decrement count
          JNZ REPEAT    ;jump to repeat if not equal to zero
          HLT           ;Terminate Program


Post a Comment

0 Comments