SORTING
ASCENDING ORDER
AIM:
To write an assembly language program for the sorting in ascending & descending order
ALGORITHM: (ASCENDING ORDER)
1. Star the program
2. Move data to CX register and move CX data to D1 register
3. Move 1200 to the BX register and move the content of 1200 to memory of AX
4. Compare the content of AX with 1202
5. Jump on borrow to rep
6. Move the data in memory to AX and move Data from AX to AI
7. Add Data to BX register and go to loop2
8. Perform no operation and move data & D1 to CX
9. Go to the loop
10. Stop the program
PROGRAM:
ADDRESS | LABEL | OPCODE | MNEMONICS | OPERAND | COMMENTS | ||
1000 | | B9, 07, 00 | MOV | CX, 07 | Move data to cx reg | ||
1003 | LOOP1 | 89 CF | MOV | DI, CX | Move cx data to direg | ||
1005 | | BB, 00, 12 | MOV | BX, 1200 | Move 1200 to the bx reg | ||
1008 | LOOP2 | 8B, 07 | MOV | AX, AI [BX] | Move the content of 1200 to memory of ax | ||
100A | | 3B, 47, 02 | CMP | AX,AI[BX+2] | Compare the content of ax with 1202 | ||
100D | | 72, 05 | JB | REP | jump on borrow to rep | ||
100F | | 87, 47, 02 | XCHG | AX,AI[BX+2] | Move the data in memory to ax | ||
1012 | | 89, 07 | MOV | AI[BX],AX | Move data from ax to ai | ||
101A | REP | 83, C3, 02 | ADD | BX,2 | Add data to bx register | ||
1017 | | F2, EF | LOOP | LOOP2 | Go to loop2 | ||
1019 | | 90 | NOP | | No operation | ||
101A | | 89, F9 | MOV | CX, DI | Move data of di to cx | ||
101C | | E2, E5 | LOOP | LOOP1 | Go to loop1 | ||
101E | | F4 | HLT | | Stop the process | ||
DESCENDING ORDER:
ALGORITHM:
1. Start the process
2. Move the data to CX register and move CX content to D1 register
3. Move the address to BX register and move the count of 1200 to AX
4. Compare the content of AX with 1202`
5. Jump on no borrow to REP
6. Exchange AX and A1 register and move AX register to BX
7. Add BX register to 2 and continue the loop up to CX is zero
8. Perform no operation and move D1 register to CX register and continue the loop up to CX is zero
9. Stop the program
PROGRAM:
ADDRESS | LABEL | OPCODE | MNEMONICS | OPERAND | COMMENTS | ||
1000 | | B9, 07, 00 | MOV | CX, 07 | Move data to cx reg | ||
1003 | LOOP1 | 89 CF | MOV | DI, CX | Move cx data to direg | ||
1005 | | BB, 00, 12 | MOV | BX, 1200 | Move 1200 to the bx reg | ||
1008 | LOOP2 | 8B, 07 | MOV | AX, AI [BX] | Move the content of 1200 to memory of ax | ||
100A | | 3B, 47, 02 | CMP | AX,AI[BX+2] | Compare the content of ax with 1202 | ||
100D | | 73, 05 | JNB | REP | Jump on borrow to rep | ||
100F | | 87, 47, 02 | XCHG | AX,AI[BX+2] | Move the data in memory to ax | ||
1012 | | 89, 07 | MOV | AI [BX], AX | Move data from ax to ai | ||
101A | REP | 83, C3, 02 | ADD | BX,2 | Add data to bx register | ||
1017 | | F2, EF | LOOP | LOOP2 | Go to loop2 | ||
1019 | | 90 | NOP | | No operation | ||
101A | | 89, F9 | MOV | CX,DI | Move data of di to cx | ||
101C | | E2, E5 | LOOP | LOOP1 | Go to loop1 | ||
101E | | F4 | HLT | | Stop the process | ||
ASCENDING ORDER DESCENDING ORDER
INPUT: INPUT: 1200 - 0002
1200 – 0007 1208 – 0003 1202 – 0006 1208 - 0078
1202 – 0006 120A – 0002 1204 – 00A1 120A - 0012
1204 – 0005 120C – 0001 1206 – 00C2 120C - 0011
1206 – 0004
OUTPUT: OUTPUT: 1200 – 00C2
1202 – 0002 1204 – 0078
1204 – 0003 1206 - 0012
1206 – 0004 1208 - 0011
1208 – 0005 120A - 0006
120A – 0006 120C - 0002
RESULT:
Thus the assembly language programs for sorting- ascending & descending order was executed are verified.
0 comments:
Post a Comment