内容发布更新时间 : 2024/11/8 3:05:20星期一 下面是文章的全部内容请认真阅读。
CODE ENDS END START
13. 将键盘上输入的一位为十六进制数转换成十进制数,在屏幕上显示。 DATA SEGMENT DATA1 DB 10 DUP(?) DATA2 DB 10 DUP(?) DATA ENDS
STACK SEGMENTSTACK
DB 100 DUP(?)
STACK ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK START:PUSH DS
MOV AX,DATA
MOV DS,AX KEY: MOV AH,1 INT 21H ZH: CMP AL,3AH JAE ZH1
SUB AL,30H JMP ZH2
ZH1: SUB AL,37H ADD AL,0 DAA
ZH2: MOV BL,AL AND AL,0F0H MOV CL,4 SHR AL,CL ADD AL,30H MOV BH,AL MOVAL,BL AND AL,0FH ADD AL,30H
MOVBL,AL DISP: MOV DL,BH
MOV AH,2 INT 21H MOV DL,BL MOV AH,2 INT 21H POP DS
MOV AH,4CH INT 21H HLT
CODE ENDS
END START 调试程序:
STACK SEGMENT STACK DB 100 DUP(?) STACK ENDS DATA SEGMENT
BUF1 DB 'Please input one hexadecimal(0-9,A-F):',0DH,0AH,'$' BUF2 DB 20H,20H,'Decimal(0-15):',0DH,0AH,'$' BUF3 DB 10 DUP(?) DATA ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK START: PUSH DS
MOV AX,DATA MOV DS,AX
MOV DX,OFFSET BUF1 MOV AH,9 INT 21H
KEY: MOV AH,1 INT 21H PUSH AX
MOV DX,OFFSET BUF2 MOV AH,9 INT 21H POP AX
ZH: CMP AL,3AH JAE ZH1 SUB AL,30H JMP ZH2 ZH1: SUB AL,37H ADD AL,0 DAA
ZH2: MOV BL,AL AND AL,0F0H MOV CL,4 SHR AL,CL ADD AL,30H MOV BH,AL MOV AL,BL AND AL,0FH ADD AL,30H
MOV BL,AL DISP: MOV DL,BH MOV AH,2 INT 21H MOV DL,BL MOV AH,2 INT 21H POP DS MOV AH,4CH INT 21H HLT CODE ENDS
END START
22. 编程序统计学生的数学成绩,分别归类90~99分,80~89分,70~79分,60~69分及60分以下,并将各段的人数送入内存单元中。 解:
STACK SEGMENT
DB 100 DUP(?)
STACK ENDS DATA SEGMENT DATA1 DB 200 DUP(?) DATA2 DB 100 DUP(?) DATA3 DB 10 DUP(?) DATA ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK START:PUSH DS
MOV AX,DATA MOV DS,AX XOR CX,CX
KEY:MOV SI,OFFSET DATA1 KEY1:MOV AH,1 INT 21H CMP AL,‘$’ JZ ZH INC CX
MOV [SI],AL
INC SI
JMP KEY1
ZH: MOV SI,OFFSET DATA1 MOV DI,OFFSET DATA2 SHR CX,1 PUSH CX
ZH1:MOV AL,[SI]
AND AL,0FH SHL AL,1 SHL AL,1 SHL AL,1 SHL AL,1 MOV BL,AL INC SI
MOV AL,[SI] AND AL,0FH OR AL,BL MOV [DI],AL INC SI INC DI
LOOP ZH1
TJ: POP CX
MOV DI,OFFSET DATA2 TJ0: MOV AL,[DI]
CMP AL,90H
JNB TJ1
CMP AL,80H
JNB TJ2
CMP AL,70H
JNB TJ3
CMP AL,60H
JNB TJ4
INC 4[DATA3] JMP TJ5
TJ1: INC [DATA3] JMP TJ5
TJ2: INC 1[DATA3] JMP TJ5
TJ3: INC 2[DATA3] JMP TJ5
TJ4: INC 3[DATA3] TJ5: INC DI LOOP TJ0 POP DS
MOV AH,4CH INT 21H HLT
CODE ENDS
END START 调试程序:
STACK SEGMENT STACK DB 100 DUP(?) STACK ENDS DATA SEGMENT DATA1 DB 80 DUP(?) DATA2 DB 80 DUP(?) DATA3 DB 10 DUP(?) DATA ENDS CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK START: PUSH DS
MOV AX,DATA
MOV DS,AX XOR CX,CX
KEY:MOV SI,OFFSET DATA1 KEY1:MOV AH,1 INT 21H CMP AL,'$' JZ ZH INC CX
MOV [SI],AL INC SI
JMP KEY1
ZH: MOV SI,OFFSET DATA1 MOV DI,OFFSET DATA2 SHR CX,1 PUSH CX
ZH1:MOV AL,[SI]
AND AL,0FH SHL AL,1 SHL AL,1 SHL AL,1 SHL AL,1 MOV BL,AL INC SI
MOV AL,[SI] AND AL,0FH OR AL,BL MOV [DI],AL INC SI INC DI
LOOP ZH1
TJ: POP CX
MOV DI,OFFSET DATA2 TJ0: MOV AL,[DI] CMP AL,90H JNB TJ1 CMP AL,80H JNB TJ2 CMP AL,70H JNB TJ3 CMP AL,60H JNB TJ4
INC 4[DATA3] JMP TJ5 TJ1: INC [DATA3] JMP TJ5 TJ2: INC 1[DATA3] JMP TJ5 TJ3: INC 2[DATA3] JMP TJ5 TJ4:INC 3[DATA3] TJ5: INC DI
LOOP TJ0 POP DS
MOV AH,4CH INT21H