《微机原理与接口技术》(第四版)周何琴课后习题答案 下载本文

MOV DL, BL MOV AH, 2 INT 21H

MOV DL, BH INT 21H POP AX RET DISP ENDP

调试程序

STACK SEGMENT STACK DB 100 DUP(?) STACK ENDS DATA SEGMENT

DA1 DB 5FH, 0A4H, 0C7H DA2 DB 100 DUP(?) DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA,SS:STACK START: PUSH DS

MOV AX,DATA MOV DS,AX MOV DL,DA1 CALL CON CALL DISP POP DS HLT CON:

PUSH AX PUSH CX MOV CL,4 MOV AL,DL AND AL,0FH CMP AL,0AH JNC LP1 ADD AL,30H JMP LP2 LP1: ADD AL,37H LP2: MOV BL,AL MOV AL,DL SHR AL,CL AND AL,0FH CMP AL,0AH JNC LP3 ADD AL,30H JMP LP4 LP3: ADD AL,37H LP4: MOV BH,AL POP CX POP AX RET

25

DISP:

PUSH AX MOV DL,BL MOV AH,2 INT 21H MOV DL,BH INT 21H POP AX RET CODE ENDS END START

13. 将键盘上输入的一位为十六进制数转换成十进制数,在屏幕上显示。 DATA SEGMENT

DATA1 DB 10 DUP(?) DATA2 DB 10 DUP(?) DATA ENDS

STACK SEGMENT STACK

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 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

26

调试程序:

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

27

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] 28