单片机编程-------试编程使20H~4FH的数据块按降序排列。
答案:1 悬赏:0 手机版
解决时间 2021-07-16 11:18
- 提问者网友:不爱我么
- 2021-07-16 03:42
试编程使20H~4FH的数据块按降序排列
最佳答案
- 五星知识达人网友:等灯
- 2021-07-16 03:55
DATA SEGMENT
NUM DW 20 DUP(?) ;存输入数列
I DW 0 ;数列个数
MAX DW ?
CHAR3 DB 'The order of the numbers is:$'
CHAR4 DB 'input number:$',0DH,0AH
REC DB 5 DUP(?) ;输出缓存
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:PUSH DS
MOV AX,DATA
MOV DS,AX
LEA DX,CHAR4
MOV AH,09H
INT 21H
MOV SI,0
MOV BX,0
INPUT:MOV AH,01H
iNT 21H
CMP AL,20H
JZ WRITE1
CMP AL,0DH
JZ WRITE2
SUB AL,30H
MOV CL,AL
MOV CH,00H
MOV AX,BX
MOV BX,0AH
MUL BX
MOV BX,AX
ADD BX,CX
JMP INPUT
WRITE1:MOV [NUM+SI],BX
ADD SI,2
INC I
MOV BX,0
JMP INPUT
WRITE2:MOV [NUM+SI],BX
ADD SI,2
INC I
MOV DL,0AH
MOV AH,02H
INT 21H
MOV CX,I
DEC CX
LOOP1:MOV DI,CX
MOV BX,0
LOOP2:MOV AX,NUM[BX]
CMP AX,NUM[BX+2]
JBE CONTINUE
XCHG AX,NUM[BX+2]
MOV NUM[BX],AX
CONTINUE:ADD BX,2
LOOP LOOP2
MOV CX,DI
LOOP LOOP1
INITNUM: LEA DX,CHAR3
MOV AH,09H
INT 21H
MOV CX,I
MOV DI,0
LOOPNUM:MOV AX,[NUM+DI]
ADD DI,2
MOV BX,10
MOV SI,4
CHANGENUM: MOV DX,0
DIV BX
MOV [REC+SI],DL
DEC SI
CMP AX,0
JA CHANGENUM
OUTPUTNUM: ;输出(从initnum开始,做预备工作)
INC SI
MOV DL,[REC+SI]
ADD DL,30H
MOV AH,02H
INT 21H
CMP SI,4
JB OUTPUTNUM
MOV DL,20H
MOV AH,02H
INT 21H
LOOP LOOPNUM
STOP:
MOV AH,4CH
INT 21H
CODE ENDS
END START
NUM DW 20 DUP(?) ;存输入数列
I DW 0 ;数列个数
MAX DW ?
CHAR3 DB 'The order of the numbers is:$'
CHAR4 DB 'input number:$',0DH,0AH
REC DB 5 DUP(?) ;输出缓存
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:PUSH DS
MOV AX,DATA
MOV DS,AX
LEA DX,CHAR4
MOV AH,09H
INT 21H
MOV SI,0
MOV BX,0
INPUT:MOV AH,01H
iNT 21H
CMP AL,20H
JZ WRITE1
CMP AL,0DH
JZ WRITE2
SUB AL,30H
MOV CL,AL
MOV CH,00H
MOV AX,BX
MOV BX,0AH
MUL BX
MOV BX,AX
ADD BX,CX
JMP INPUT
WRITE1:MOV [NUM+SI],BX
ADD SI,2
INC I
MOV BX,0
JMP INPUT
WRITE2:MOV [NUM+SI],BX
ADD SI,2
INC I
MOV DL,0AH
MOV AH,02H
INT 21H
MOV CX,I
DEC CX
LOOP1:MOV DI,CX
MOV BX,0
LOOP2:MOV AX,NUM[BX]
CMP AX,NUM[BX+2]
JBE CONTINUE
XCHG AX,NUM[BX+2]
MOV NUM[BX],AX
CONTINUE:ADD BX,2
LOOP LOOP2
MOV CX,DI
LOOP LOOP1
INITNUM: LEA DX,CHAR3
MOV AH,09H
INT 21H
MOV CX,I
MOV DI,0
LOOPNUM:MOV AX,[NUM+DI]
ADD DI,2
MOV BX,10
MOV SI,4
CHANGENUM: MOV DX,0
DIV BX
MOV [REC+SI],DL
DEC SI
CMP AX,0
JA CHANGENUM
OUTPUTNUM: ;输出(从initnum开始,做预备工作)
INC SI
MOV DL,[REC+SI]
ADD DL,30H
MOV AH,02H
INT 21H
CMP SI,4
JB OUTPUTNUM
MOV DL,20H
MOV AH,02H
INT 21H
LOOP LOOPNUM
STOP:
MOV AH,4CH
INT 21H
CODE ENDS
END START
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯