name "sort" ; simple sort ; this program inputs 3 numbers and ; sorts them from largest to smallest ; this macro prints a char in AL and advances ; the current cursor position: putc macro char push ax mov al, char mov ah, 0eh int 10h pop ax endm ; this macro sets current cursor position: gotoxy macro col, row push ax push bx push dx mov ah, 02h mov dh, row mov dl, col mov bh, 0 int 10h pop dx pop bx pop ax endm data segment cr equ 0dh lf equ 0ah dollar equ '$' new_line db lf, cr, dollar msg1 db "enter first value (-32768..32767)!" db lf, cr, dollar msg2 db lf, cr, "enter second value (-32768..32767)!" db lf, cr, dollar msg3 db lf, cr, "enter third value (-32768..32767)!" db lf, cr, dollar msg4 db cr, lf, cr, lf, "after sorting from biggest to smallest:", dollar msg5 db cr, lf, "num1 = ", dollar msg6 db cr, lf, "num2 = ", dollar msg7 db cr, lf, "num3 = ", dollar num1 dw ? num2 dw ? num3 dw ? ends stack segment dw 100h dup(?) ends code segment start proc far ; prepare for return to os: push ds mov ax, 0 push ax ; set segment registers: mov ax, data mov ds, ax mov es, ax ; clear the screen: call clear_screen ; position the cursor at row=3 and column=0 gotoxy 0, 3 ; ask for first number: lea dx, msg1 call puts ; display the message. call scan_num ; input the number into cx. mov num1, cx ; ask for second number: lea dx, msg2 call puts ; display the message. call scan_num ; input the number into cx. mov num2, cx ; ask for third number: lea dx, msg3 call puts ; display the message. call scan_num ; input the number into cx. mov num3, cx ; sorting: mov bx, num1 mov cx, num2 call sort ; exchange if bx