Micro Lab
Micro Lab
_DATA segment
cr equ 0dh ; Carriage return
lf equ 0ah ; Line feed
msg1 db ’Number of elements <XX>: $’ ; Message to prompt for number of elements
msg2 db cr, lf, ’Enter element <XX>: $’ ; Message to prompt for each element
msg3 db cr, lf, ’Elements in descending order...$’ ; Message for sorted output
count db ? ; Variable to store the count of numbers
tabl dw 20 dup(0) ; Array to store the numbers (max 20, word-sized for 3 digits)
tnum dw ? ; Temporary variable for input
resdisp db 6 dup(0) ; Buffer for displaying results
_DATA ends
_CODE segment
assume cs: _CODE, ds: _DATA
start:
; Initialize data segment
mov ax, _DATA
mov ds, ax
mov count,05h
dec count
mov bx, 0000h
mov ch, count
back1:
mov ax,0000h
mov bx,0000h
mov ax, [si]
mov bx, [si+2]
cmp ax, bx
jge skip ; NOTICE : Jodi assending order e sorting korte chaw tahole ei jaygay ’jle skip’ likhlei hobe
dec ch
jnz back2
inc count
mov cx,00h
mov cl, count
mov bx, 0 ; Start displaying from tabl[0]
mov si, offset resdisp
printstring msg3
prnxt:
mov ax, tabl[bx] ; Get the number
call hex2asc ; Convert to ASCII and store in resdisp
printstring resdisp ; Display the number
add bx, 2 ; Move to next number
loop prnxt ; Repeat for all numbers
; Exit program
mov ah, 4ch
mov al, 00h
int 21h
int 03h
_CODE ends
end start