汇编语言:输入一个字符串(以回车符作为结束),将其排序后输出到屏幕上
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
ASSUME CS:CCC, DS:QWER
QWER SEGMENT
MSG1 DB 'PLEASE INPUT STRING:', 0DH, 0AH, '$'
MSG2 DB 0DH, 0AH, 'AFTER SORT:', 0DH, 0AH, '$'
;----------------------------------
BUFSIZE DB 80
ACTLEN DB ?
CHARS DB 80 DUP(20H)
QWER ENDS
;----------------------------------
CCC SEGMENT
MAIN PROC FAR
START:
MOV AX, QWER
MOV DS, AX
MOV DX, OFFSET MSG1
MOV AH, 9
INT 21H
MOV DX, OFFSET BUFSIZE
MOV AH, 0AH
INT 21H
;-----------------------
MOV CL, ACTLEN
CMP CL, 0
JNZ OK
JMP EXIT_MAIN
OK:
MOV DX, OFFSET MSG2
MOV AH, 9
INT 21H
;-----------------------
CALL SORT
;-----------------------
XOR CX, CX
MOV CL, ACTLEN
MOV BX, OFFSET CHARS
ADD BX, CX
MOV BYTE PTR [BX], '$'
MOV DX, OFFSET CHARS
MOV AH, 09H
INT 21H
EXIT_MAIN:
MOV AH, 4CH
INT 21H
MAIN ENDP
;----------------------------------
SORT PROC
XOR CX, CX
MOV CL, ACTLEN
DEC CX
MOV SI, OFFSET CHARS
S: PUSH CX
MOV DI, SI
S1: MOV AL, [DI]
INC DI
CMP AL, [DI]
JB JX
XCHG AL, [DI]
MOV [DI - 1], AL
JX:
LOOP S1
POP CX
LOOP S
RET
SORT ENDP
;----------------------------------
CCC ENDS
END START
QWER SEGMENT
MSG1 DB 'PLEASE INPUT STRING:', 0DH, 0AH, '$'
MSG2 DB 0DH, 0AH, 'AFTER SORT:', 0DH, 0AH, '$'
;----------------------------------
BUFSIZE DB 80
ACTLEN DB ?
CHARS DB 80 DUP(20H)
QWER ENDS
;----------------------------------
CCC SEGMENT
MAIN PROC FAR
START:
MOV AX, QWER
MOV DS, AX
MOV DX, OFFSET MSG1
MOV AH, 9
INT 21H
MOV DX, OFFSET BUFSIZE
MOV AH, 0AH
INT 21H
;-----------------------
MOV CL, ACTLEN
CMP CL, 0
JNZ OK
JMP EXIT_MAIN
OK:
MOV DX, OFFSET MSG2
MOV AH, 9
INT 21H
;-----------------------
CALL SORT
;-----------------------
XOR CX, CX
MOV CL, ACTLEN
MOV BX, OFFSET CHARS
ADD BX, CX
MOV BYTE PTR [BX], '$'
MOV DX, OFFSET CHARS
MOV AH, 09H
INT 21H
EXIT_MAIN:
MOV AH, 4CH
INT 21H
MAIN ENDP
;----------------------------------
SORT PROC
XOR CX, CX
MOV CL, ACTLEN
DEC CX
MOV SI, OFFSET CHARS
S: PUSH CX
MOV DI, SI
S1: MOV AL, [DI]
INC DI
CMP AL, [DI]
JB JX
XCHG AL, [DI]
MOV [DI - 1], AL
JX:
LOOP S1
POP CX
LOOP S
RET
SORT ENDP
;----------------------------------
CCC ENDS
END START
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询