æ±ç¼è¯è¨ï¼æ±æ大å¼ãæå°å¼ãä¸å¼ï¼åè代ç åç¨åºç¸å
³æ³¨éå¦ä¸:
éè¿é®çè¾å
¥7个ä¸ç¸ççæ°æ®ï¼æ°æ®åä»äº0-255ä¹é´ï¼ï¼å°æå°å¼ãæ大å¼åä¸å¼æ¾ç¤ºå¨å±å¹ä¸;
; å®ä¹å¸¸é
Yes equ 1
No equ 0
On equ 1
Off equ 0
CR equ 0DH
LF equ 0AH
KBBack equ 8
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; å®ä¹ç»æç±»å
Bubb_Para Struc ; å泡æåºæ³åæ°è¡¨
Carry DB No ; æ¯å¦å¸¦ç¬¦å·ãYesï¼æ符å·æ°ï¼Noï¼æ 符å·æ°
Sort DB No ; ååº/éåºãYesï¼ååºï¼Noï¼éåº
Yes_No DB 73h,76h,7dh,7eh
Load DB 0ach,0adh
Comp DB 3ah,3bh
Exchange DB 86h,87h
Store DB 0aah,0abh
Bubb_Para EndS
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼æè¦æ±å¯¹æ°ç»å
ç´ æåºï¼è½å¤å¯¹åèå
ç´ ãåå
ç´ è¿è¡æ 符å·æ°ãæ符å·æ°çååºãéåºæåºã
; åç¨åºååï¼å¯¹åèå
ç´ è¿è¡æ 符å·ååºæåºã
Bubbling Proc Near
PUSH AX
PUSH BX
PUSH CX
PUSH SI
PUSH DI
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼æ ¹æ®æåºåæ°ï¼ä¿®æ¹æåºæ令
LEA SI,Parameters
LEA DI,@@Compare
MOV AL,TYPE Number
DEC AL
PUSH AX
LEA BX,[SI.Load]
XLAT
MOV [DI][2],AL
POP AX
PUSH AX
LEA BX,[SI.Comp]
XLAT
MOV [DI][3],AL
POP AX
PUSH AX
LEA BX,[SI.Exchange]
XLAT
MOV [DI][7],AL
POP AX
LEA BX,[SI.Store]
XLAT
MOV [DI][9],AL
MOV AL,[SI.Carry]
SHL AL,1
OR AL,[SI.Sort]
XOR AH,AH
LEA BX,[SI.Yes_No]
XLAT
MOV [DI][5],AL
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼æè¦æ±æåº
MOV CX,Elements-1 ;å¤å¾ªç¯æ¬¡æ°
@@Scanning: PUSH CX ;å
¥æ ä¿åå¤å¾ªç¯æ¬¡æ°
LEA SI,Number ;æ°ç»é¦å°åè£
å
¥æºååå¯åå¨
@@Compare: PUSH SI
POP DI ;å½åæ°ç»å
ç´ å°åèµç»ç®çååå¯åå¨ï¼ä»¥å¤äº¤æ¢ä¹ç¨
LODSB ;å°å½åæ°ç»å
ç´ è¯»å
¥ç´¯å å¨
CMP AL,[SI] ;å½åæ°ç»å
ç´ ä¸ç¸é»çä¸ä¸ä¸ªæ°ç»å
ç´ ç¸æ¯è¾
JBE @@NextOne ;è¥å°äºæçäºï¼ä¸ä½æ°æ®äº¤æ¢ï¼å¤çä¸ä¸ä¸ªæ°ç»å
ç´
XCHG AL,[SI] ;è¥å¤§äºï¼äº¤æ¢æ°ç»å
ç´
STOSB ;ä¿åæ°å¼è¾å°è
@@NextOne: LOOP @@Compare ;å¤çä¸ä¸ä¸ªæ°ç»å
ç´
POP CX ;å¤å¾ªç¯æ¬¡æ°åºæ
LOOP @@Scanning ;ä¸ä¸è¶æ¯è¾
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
POP DI
POP SI
POP CX
POP BX
POP AX
RET
Bubbling EndP
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼æ¾
示æå®å°åï¼Str_Addrï¼çå符串
; å
¥å£ï¼
; Str_Addrï¼å符串å°åï¼è¦æ±å¨æ°æ®æ®µï¼
; ç¨æ³: Output Str_Addr
; ç¨æ³ä¸¾ä¾ï¼Output PromptStr
Output MACRO Str_Addr
lea dx,Str_Addr
mov ah,9
int 21h
EndM
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼åå
æ ä½ç½®
; å
¥å£ï¼æ
; åºå£ï¼DH=è¡å·ï¼DL=åå·
GetCursor Proc Near
PUSH AX
PUSH BX
PUSH CX
XOR BX,BX
MOV AH,3
INT 10H
MOV Cursor_Row,DH
MOV Cursor_Col,DL
POP CX
POP BX
POP AX
RET
Cursor_Row DB ?
Cursor_Col DB ?
GetCursor EndP
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼ç½®å
æ ä½ç½®
; å
¥å£ï¼Cursor_Row=è¡åæ ; Cursor_Col: ååæ )
SetCursor Proc Near
PUSH CX
PUSH BX
PUSH AX
MOV DH,Cursor_Row
MOV DL,Cursor_Col
XOR BX,BX
MOV AH,2
INT 10H
POP AX
POP BX
POP CX
RET
SetCursor EndP
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼è¾åºå车æ¢è¡
enter_CTLF proc Near
push ax
push dx
mov ah,02h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop ax
ret
enter_CTLF endp
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼é®çè¾å
¥ä¸ä¸ªNä½çåè¿å¶æ°åï¼
; æ°æ®è¾å
¥è¯´æï¼
; 1ãè¾è¶³Nä½çï¼ä¸ç¨å车ï¼èªç¶ç»ææ¬æ°æ®è¾å
¥ï¼
; 2ãä¸è¶³Nä½çï¼éå车ç»ææ¬æ°æ®è¾å
¥
; å
¥å£ï¼N=æ°åä½æ°ï¼di=ä¿åè¾å
¥çæ°åé¦å°å
; åºå£ï¼è½¬æ¢åçäºè¿å¶æ°ä¿åå¨diææçåå
Input_Digit Proc Near
push dx
push cx
push bx
push di
lea di,@@Save_Tmp
push di
cld
mov cx,N
push cx
@@Input: call GetCursor ;åå
æ ä½ç½®
mov ah,1 ;ä»é®çæ¥åä¸ä¸ªå符
int 21h
cmp al,CR ;è¥é®å
¥çæ¯å车ï¼å·²ç»é®å
¥çæ°åä¸è¶³Nä½
jz @@ASC_Dec ;转å»å¤çå·²ç»é®å
¥çæ°å
cmp al,KBBack
jz @@KB_Back ;è¥æ¯å空é®ï¼éæ°è¾å
¥
cmp al,'0'
jb @@KBBack ;è¥ä½äºæ°å'0'ï¼éæ°è¾å
¥
cmp al,'9'
ja @@KBBack ;è¥ä½äºæ°å'9'ï¼éæ°è¾å
¥
jmp @@Save_Dig
@@KB_Back: dec Cursor_Col
inc cx
dec di
@@KBBack: call SetCursor ;ç½®å
æ ä½ç½®
jmp @@Input
@@Save_Dig: and al,0fh ;转æ¢æäºè¿å¶æ°
stosb ;ä¿å
loop @@Input ;æ¥åä¸ä¸ä¸ªæ°å
@@ASC_Dec: mov ax,cx
pop cx
pop si
sub cx,ax ;å®é
è¾
å
¥çæ°åä½æ°
xor dx,dx
xor ax,ax
jcxz @@Save_Ret ;è¥ç´æ¥å车ï¼æ²¡æè¾å
¥ä»»ä½æ°åï¼æè¾å
¥'0'å¤ç
dec cx ;å®é
è¾å
¥çæ°åä½æ°å1ï¼åå¤æè¾å
¥çè¿ä¸ä¸²æ°å转æ¢æäºè¿å¶æ°
mov bl,10
@@Mul_Ten: lodsb
cbw
add ax,dx
mul bl
mov dx,ax
loop @@Mul_Ten
lodsb
cbw
add ax,dx
@@Save_Ret: pop di
stosb
pop bx
pop cx
pop dx
ret
@@Save_Tmp db 16 dup(?)
Input_Digit EndP
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
; åè½ï¼æALä¸çäºè¿å¶æ 符å·æ°è½¬æ¢ææ¾å¼çåè¿å¶ASCIIç
; å
¥å£ï¼AL=äºè¿å¶æ°ï¼di=转æ¢åçASCIIä¿åå°å
; åºå£ï¼æ
Dec_ASCII Proc Near
push si
push cx
push bx
push di
mov bl,10
xor cx,cx
lea di,@@Temp_Save[3]
cld
@@Divide: xor ah,ah
div bl
or ah,30h
mov [di],ah
dec di
inc cx
test al,0ffh
jnz @@Divide
push di
pop si
inc si
pop di
pop bx
push di
rep movsb
mov byte ptr [di],'$'
pop di
pop cx
pop si
ret
@@Temp_Save db 4 dup(?)
Dec_ASCII EndP
; ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
N equ 3 ;æ°åä½æ°ï¼ä»äº0-255ä¹é´çæ 符å·æ°ï¼
Elements equ 7 ;æ°æ®ä¸ªæ°
PromptStr db 'Please Enter ',N or 30h,' digits for ',Elements or 30h,' numbers: $'
Max_Num db 13,10,13,10,'The maximum is $'
Mix_Num db 13,10,13,10,'The miximum is $'
Mid_Num db 13,10,13,10,'The midoule is $'
Number db Elements dup(?) ;ä»é®çæ¥åçElements个Nä½æ°å
Parameters Bubb_Para <No,No> ;æ 符å·æ°éåºæåº
Start: push cs
pop ds
push cs
pop es ;使æ°æ®æ®µãéå 段ä¸ä»£ç 段å段
; éè¿é®çè¾å
¥7个ä¸ç¸ççæ°æ®ï¼æ°æ®åä»äº0-255ä¹é´ï¼ï¼å°æå°å¼ãæ大å¼åä¸å¼æ¾ç¤ºå¨å±å¹ä¸
Output PromptStr ;æ示è¾å
¥Elements个Nä½æ°å
lea di,Number ;æ°ååæ¾å°å
mov cx,Elements ;æ°æ®ä¸ªæ°
Read_Number:call enter_CTLF ;è¾å
¥ä¸ä¸ªå车ãæ¢è¡
call Input_Digit ;ä»é®çæ¥åæå®ä½æ°çæ°æ®
loop Read_Number
call Bubbling ;æ 符å·æ°éåºæåº
Output Max_Num ;æ大å¼
mov al,Number ;åæ大å¼
lea di,Temp_STr ;æ¾å¼çåè¿å¶ASCIIç å符串æåå°å
call Dec_ASCII ; æALä¸çäºè¿å¶æ 符å·æ°è½¬æ¢ææ¾å¼çåè¿å¶ASCIIç
Output Temp_STr ;æ¾ç¤ºæ大å¼
Output Mix_Num ;æå°å¼
mov al,Number[Elements-1] ;åæå°å¼
lea di,Temp_STr ;æ¾å¼çåè¿å¶ASCIIç å符串æåå°å
call Dec_ASCII ; æALä¸çäºè¿å¶æ 符å·æ°è½¬æ¢ææ¾å¼çåè¿å¶ASCIIç
Output Temp_STr ;æ¾ç¤ºæå°å¼
Output Mid_Num ;ä¸å¼
mov al,Number[(Elements-1)/2] ;åä¸å¼
lea d
i,Temp_STr ;æ¾å¼çåè¿å¶ASCIIç å符串æåå°å
call Dec_ASCII ; æALä¸çäºè¿å¶æ 符å·æ°è½¬æ¢ææ¾å¼çåè¿å¶ASCIIç
Output Temp_STr ;æ¾ç¤ºä¸å¼
Exit_Proc: mov ah,4ch ;ç»æç¨åº
int 21h
Temp_STr:
Code ENDS
END Start ;ç¼è¯å°æ¤ç»æ
温馨提示:答案为网友推荐,仅供参考