将一段内存中的数据从大到小排序,再依次显示。运行后结果不对。请指出错误啊,还要改进哪些地方?

发布网友 发布时间:2022-04-26 23:04

我来回答

1个回答

热心网友 时间:2023-11-11 13:03

将一段内存中的数据从大到小排序,再依次显示。

DATA SEGMENT
BUF DB 10H, 25H, 32H, 4FH, 13H, 43H
DATA ENDS
STACK SEGMENT STACK 'STACK'
SB DB 100 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STACK
START:
MOV AX, STACK
MOV SS, AX
MOV AX, DATA
MOV DS, AX
LEA DI, BUF
MOV BL, 5
AGN:
MOV SI, DI
MOV CL, BL
AGN2:
MOV AL, [SI]
CMP AL, [SI + 1]
JNC AGN3
XCHG [SI + 1], AL
MOV [SI], AL
AGN3:
INC SI
DEC CL
JNZ AGN2
DEC BL
JNZ AGN
;-------------------------
MOV CH, 06H
MOV CL, 04H
MOV AH, 02H
NEXT:
MOV DL, [DI]
ROL DL, CL
AND DL, 0FH
CMP DL, 0AH
JB STORE
ADD DL, 07H
STORE:
ADD DL, 30H
INT 21H
;---------------
MOV DL, [DI]
AND DL, 0FH
CMP DL, 0AH
JB STORE2
ADD DL, 07H
STORE2:
ADD DL, 30H
INT 21H
MOV DL, ','
INT 21H
INC DI
DEC CH
JNE NEXT
;-------------------------
MOV AH, 4CH
INT 21H

CODE ENDS
END START

程序运行结果:
c:\masm510>SS
4F,43,32,25,13,10,
c:\masm510>

热心网友 时间:2023-12-03 14:01

将一段内存中的数据从大到小排序,再依次显示。

DATA SEGMENT
BUF DB 10H, 25H, 32H, 4FH, 13H, 43H
DATA ENDS
STACK SEGMENT STACK 'STACK'
SB DB 100 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:STACK
START:
MOV AX, STACK
MOV SS, AX
MOV AX, DATA
MOV DS, AX
LEA DI, BUF
MOV BL, 5
AGN:
MOV SI, DI
MOV CL, BL
AGN2:
MOV AL, [SI]
CMP AL, [SI + 1]
JNC AGN3
XCHG [SI + 1], AL
MOV [SI], AL
AGN3:
INC SI
DEC CL
JNZ AGN2
DEC BL
JNZ AGN
;-------------------------
MOV CH, 06H
MOV CL, 04H
MOV AH, 02H
NEXT:
MOV DL, [DI]
ROL DL, CL
AND DL, 0FH
CMP DL, 0AH
JB STORE
ADD DL, 07H
STORE:
ADD DL, 30H
INT 21H
;---------------
MOV DL, [DI]
AND DL, 0FH
CMP DL, 0AH
JB STORE2
ADD DL, 07H
STORE2:
ADD DL, 30H
INT 21H
MOV DL, ','
INT 21H
INC DI
DEC CH
JNE NEXT
;-------------------------
MOV AH, 4CH
INT 21H

CODE ENDS
END START

程序运行结果:
c:\masm510>SS
4F,43,32,25,13,10,
c:\masm510>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com