微机原理与接口第二版(陈红卫版)参考答案及复习纲要 下载本文

MOV CX,0007H

SHL BL,1 AA:SHL BL,1

JC NEXT1 MOV DL,’0’ JMP NEXT

NEXT1:MOV DL,’1’

NEXT: MOV AH,02H ;显示输出7位ASCII码值

INT 21H

LOOP AA MOV AH,4CH

INT 21H CODE ENDS

END START

12.设数据块存放在BUFFER开始的50个字节单元中,试编写程序统计数据块中正数(不包括0)的个数,并将统计的结果存放到NUMBER单元中。

解:参考程序如下: DATA SEGMENT

BUFFER DB 23H,00H,56H,89H,09H,30H DB 98H,11H,07H,? COUNT EQU $-BUFFER NUMBER DB 00H DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX MOV CX,COUNT LEA SI,BUFFER AA:MOV AL,[SI] CMP AL,00H JZ NEXT JS NEXT

INC NUMBER NEXT:INC SI

LOOP AA

MOV AH,4CH INT 21H CODE ENDS END START

13.内存的一个区域中有100个字符是用小写字母表示的,试编写一个程序,把它们转换成大写字母,并送屏幕显示。 解:参考程序如下:

DATA SEGMENT

ABC DB 61H,65H,62H,63H,?;(100个小写字母) DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX MOV CX,0064H LEA SI,ABC AA:MOV DL,[SI]

SUB DL,20H MOV [SI],DL MOV AH,02H INT 21H INC SI LOOP AA

MOV AH,4CH INT 21H

CODE ENDS END START 14.“9876”是将输入数据字符“3268”通过密码表“3589027164”加密而得,编写解密程序,求任意输入四位密码的原码。

解:参考程序如下:

DATA SEGMENT

ABC DB 33H,35H,38H,39H,30H DB 32H,37H,31H,36H,34H ABC1 DB 4DUP(00H) ABC2 DB 00H DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA

MOV DS,AX LEA SI,ABC1 LEA DI,ABC2 MOV CX,0004H AA: MOV AH,01H INT 21H MOV [SI],AL INC SI LOOP AA LEA SI,ABC1 MOV DX,0000H

MOV CX,0004H AA0: LEA BX,ABC

AA1: MOV AL,[SI] CMP AL,[BX] JZ NEXT INC BX INC DL JMP AA1 NEXT:PUSH CX

CMP CX,01H JZ NEXT1 MOV CL,04H SHL DX,CL NEXT1:POP CX LOOP AA0 MOV [DI],AX

MOV AH,4CH

INT 21H CODE ENDS END START

15.在STRING单元开始存放着一字符串,字符串以“$”结束,试编制一程序测试该字符串中是否有数字0~9,如有则将CL中的第5位置1,否则将该位清0。

解:参考程序如下:

DATA SEGMENT

ABC DB ‘ABCDS9KL$’ DATA ENDS

CODE SEGMENT ASSUME CS:CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX LEA SI,ABC MOV CL,00H AA: MOV AL,[SI]

CMP AL,’$’ JZ NEXT1 CMP AL,30H JC NEXT CMP AL,3AH JNC NEXT OR CL,20H JMP NEXT1

NEXT: INC SI JMP AA

NEXT1: MOV AH,4CH

INT 21H CODE ENDS

END START

16.编写程序完成把DX中的16进制数转换为ASCII码,并将对应的ASCII码依次存入MEM开始的存储单元中。例如,当DX的内容为2A49H时,程序执行结束后,MEM单元开始的4个字节的内容依次为39H,34H,41H,32H。

解:DATA SEGMENT

MEM DB 4 DUP(?) DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA START: MOV AX,DATA

MOV DS,AX MOV CH,04H

MOV BX,OFFSET MEM MOV CL,04H AA1:MOV AX,DX AND AL,0FH ADD AL,30H CMP AL,3AH JC NEXT ADD AL,07H NEXT:MOV [BX],AL INC BX ROR DX,CL DEC CH JNZ AA1 MOV AH,4CH INT 21H CODE ENDS END START

17.现有一个以“$”结尾的字符串,编写程序完成剔除字符串中的空格字符。 解:参考程序如下:

DATA SEGMENT

ABC DB ‘ABC DS9KL$’ DATA ENDS

CODE SEGMENT ASSUME CS:CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX LEA SI,ABC MOV BX,SI AA: MOV AL,[SI]

CMP AL,’$’ JZ NEXT

CMP AL,20H ;空格的ASCII码值为20H

JZ NEXT1 MOV AL,[SI] MOV [BX],AL INC SI INC BX JMP AA

NEXT1:INC SI

JMP AA NEXT: MOV AH,4CH

INT 21H CODE ENDS END START

18.编一程序,在STRING开头的数据区中查找WE字符串,数据区以$符作为结束符号。如查到,给出HAVE FOUND提示;如查不到,给出NOT FOUND提示。

解:参考程序如下:

DATA SEGMENT

STRING DB ‘ABCWE5$’

RE DB ‘NOT FOUND$’ RE1 DB ‘HAVE FOUND$’

DATA ENDS CODE SEGMENT

ASSUME CS:CODE,DS:DATA BEGIN:MOV AX,DATA

MOV DS,AX LEA SI,STRING

AA: MOV AL,[SI] CMP AL,’$’ JZ NEXT

CMP AL,’W’ JNZ NEXT1 INC SI MOV AL,[SI] CMP AL,’E’ JNZ AA LEA DX,RE1 JMP NEXT2 JMP AA

NEXT1:INC SI NEXT:LEA DX,RE NEXT2:MOV AH,09H

INT 21H INT 21H

MOV AH,4CH