📄 sort.asm
字号:
TITLE Simple Sort
; AUTHOR Yuri Margolin
; http://mysoft.s5.com/
;
; DATE 23/01/01
; VERSION 1.02
; FILE sort.asm
; THIS PROGRAM INPUTS 3 NUMBERS AND
; SORTS THEM FROM LARGEST TO SMALLEST
#MAKE_EXE#
; contains some common
; procedures and macros,
; (definition is done in the bottom
; of this file):
INCLUDE 'emu8086.inc'
DSEG SEGMENT 'DATA'
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:', 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 ?
DSEG ENDS
SSEG SEGMENT STACK 'STACK'
DW 100h DUP(?)
SSEG ENDS
CSEG SEGMENT 'CODE'
;****************************************
START PROC FAR
; Prepare for return to OS:
PUSH DS
MOV AX, 0
PUSH AX
; Set segment registers:
MOV AX, DSEG
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<CX
MOV num1, BX
MOV num2, CX
MOV BX, num2
MOV CX, num3
CALL SORT ; exchange if BX<CX
MOV num2, BX
MOV num3, CX
MOV BX, num1
MOV CX, num2
CALL SORT ; exchange if BX<CX
MOV num1, BX
MOV num2, CX
; Print the result:
LEA DX, MSG4
CALL PUTS
LEA DX, MSG5
CALL PUTS
MOV AX, num1
CALL PRINT_NUM ; print AX.
LEA DX, MSG6
CALL PUTS
MOV AX, num2
CALL PRINT_NUM ; print AX.
LEA DX, MSG7
CALL PUTS
MOV AX, num3
CALL PRINT_NUM ; print AX.
LEA DX, NEW_LINE
CALL PUTS
RET
START ENDP
;***********************************
; Displays the message (DX-address),
; uses DOS function to print:
PUTS PROC NEAR
PUSH AX
MOV AH, 09h
INT 21h
POP AX
RET
PUTS ENDP
;************************************
; if BX < CX then exchanges them
; (works with signed numbers)
SORT PROC NEAR
CMP BX, CX
JGE compared
XCHG BX, CX
compared:
RET
SORT ENDP
;************************************
; Definition of some common procedures
; from emu8086.inc:
DEFINE_CLEAR_SCREEN
DEFINE_PRINT_STRING
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
;*************************************
CSEG ENDS
END START
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -