CS401 Assignment 2 ...

Share:
Clear all

# [Solved] CS401 Assignment 2 (Practical) Fall 2021

Joined: 3 years ago
Posts: 6751
Topic starter

Write an assembly language program that sort digits from your VU id using selection sort:

• First store numbers of your VUID in the memory variable(array).
• Sort VUID in the ascending order using selection sort.
• After sorting each number write back to same variable declared initially.
• At the end of program the sorted id must be stored in memory.

Note: Save the .asm file with first four digits of your VUID.asm. You must use your own VUID otherwise assignment will not be accepted.

Submission details:

Following are required in a single zipped file

• Assembly language program.
• GIF showing complete process of assembling and debugging.

“Best of luck”

Solution

Code:

```; sorting a list of ten numbers using bubble sort

[org 0x0100]

jmp start

vuid: dw 6, 5, 7, 4, 9, 1, 4, 8, 2, 0

swap: db 0

start:                mov di, 0                     ; set index to zero

mov byte [swap], 0     ; set swap flag to no swaps

check:              mov ax, [vuid+di]       ; move the digit of vuid in the ax

cmp ax, [vuid+di+2]   ; compare the digit of vuid with its next digit

jbe noswap                  ; jump to noswap, if there is no need of swapping

mov bx, [vuid+di+2]   ; move second digit in bx

mov [vuid+di+2], ax   ; swap first digit  in second

mov [vuid+di], bx       ; swap second digit in first

mov byte [swap], 1     ; set the flag that a swap has been done

cmp di, 18                   ; check if we are at last index

jne check                     ; if not compare next two

cmp byte [swap], 1     ; check if a swap has been done

je start             ; if yes make another pass

end:                 mov ax, 0x4c00                      ; terminate program

int 0x21```

Students kindly share assignment files in relevant subject timely for discussion/solution.