ALP to arrange numbers in ascending order PDF

Title ALP to arrange numbers in ascending order
Author Prashant Saini
Course Microprocessor
Institution University of Mumbai
Pages 5
File Size 280.2 KB
File Type PDF
Total Downloads 483
Total Views 859

Summary

Experiment-7 Aim: Write an ALP to arrange numbers in ascending order Theory: Instructions used in this experiment are as follows: XCHG: XCHG – XCHG Destination, Source the XCHG instruction exchanges the content of a register with the content of another register or with the content of memory location...


Description

Experiment-7 Aim: Write an ALP to arrange numbers in ascending order Theory: Instructions used in this experiment are as follows: XCHG: XCHG – XCHG Destination, Source the XCHG instruction exchanges the content of a register with the content of another register or with the content of memory location(s). It cannot directly exchange the content of two memory locations. The source and destination must both be of the same type (bytes or words). The segment registers cannot be used in this instruction. This instruction does not affect any flag.  XCHG AX, DX Exchange word in AX with word in DX INC, DEC: INC – INC Destination The INC instruction adds 1 to a specified register or to a memory location. AF, OF, PF, SF, and ZF are updated, but CF is not affected. This means that if an 8-bit destination containing FFH or a 16-bit destination containing FFFFH is incremented, the result will be all 0’s with no carry. DEC- This instruction subtracts 1 from the destination word or byte. The destination can be a register or a memory location. AF, OF, SF, PF, and ZF are updated, but CF is not affected. This means that if an 8-bit destination containing 00H or a 16-bit destination containing 0000H is decremented, the result will be FFH or FFFFH with no carry (borrow) CMP: This instruction compares a byte / word in the specified source with a byte / word in the specified destination. The source can be an immediate number, a register, or a memory location. The destination can be a register or a memory location. However, the source and the destination cannot both be memory locations. The comparison is actually done by subtracting the source byte or word from the destination byte or word. The source and the destination are not changed, but the flags are set to indicate the results of the comparison. AF, OF, SF, ZF, PF, and CF

are updated by the CMP instruction. For the instruction CMP CX, BX, the values of CF, ZF, and SF will be as follows: CF ZF SF CX = BX 0 1 0 Result of subtraction is 0 CX > BX 0 0 0 No borrow required, so CF = 0 CX < BX 1 0 1 Subtraction requires borrow, so CF = 1 Using above instructions with previous learned duplicate array is created in which entered numbers copied then original array is compared with duplicate array for arranging them in a ascending order for which CMP instruction is used along with conditional instructions like JNZ,JGE and JMP. Algorithm: 1. Satrt 2. Initialize the memory location and counter. 3. Move data from memory location to any other register. 4. Move data in any of the register and compare both the data. 5. After comparing if data is small then exchange it using XCHG instruction. 6. Then the memory location is incremented and perform step 3 and decrement the counter value. 7. Perform the above steps till the counter does not reach to zero. 8. Stop Conclusion: Successfully implemented concept of array for sorting numbers in ascending order.

Source Code: DATA SEGMENT MSG1 DB 0DH,0AH,"ENTER A NUMBER : $" MSG2 DB 0AH,0DH,"NUMBER IN ASCENDING ORDER IS : $" A DB 10 DUP("$") DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START: MOV AX,DATA MOV DS,AX MOV CX,05H MOV BX,00H UP: MOV DX,OFFSET MSG1 MOV AH,09H INT 21H MOV AH,01H ;accept input from user INT 21H MOV [A+BX],AL INC BX DEC CX JNZ UP ;keeps accepting MOV CX,05H LOOP1: MOV DX,04H MOV BX,00H LOOP2: MOV AL,[A+BX] CMP AL,[A+BX+1] JGE ABOVE

CONT: INC BX DEC DX JNZ LOOP2 DEC CX JNZ LOOP1 JMP LAST ABOVE:

LAST: MOV AL,[A+BX+1] XCHG [A+BX],AL MOV [A+BX+1],AL JMP CONT MOV CL,05H MOV BX,00H MOV DX,OFFSET MSG2 MOV AH,09H INT 21H MOV DX,00H LOOP3: MOV DL,[A+BX] MOV AH,02H INT 21H INC BX DEC CL JNZ LOOP3 MOV AH,4CH INT 21H CODE ENDS END START

Output:...


Similar Free PDFs