微机原理与接口技术设计实验(12页).doc
-实验一:编写程序,比较两个字符串STRING1和STRING2所含的字符是否相同,若字符相同则显示“Match”,否则显示“No Match”参考程序:DATA SEGMENTSTRING1 DB 'HAPPY ASM'LEN EQU $-STRING1STRING2 DB 'HAPPY ASM'MESSAGE1 DB 'MATCH',0DH,0AH,'$'MESSAGE2 DB 'NO MATCH',0DH,0AH,'$'DATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATASTART:MOV AX,DATAMOV DS,AXMOV ES,AXLEA SI,STRING1LEA DI,STRING2MOV CX,LENCOMPARE:MOV AL,SIMOV BL,DICMP AL,BLJNE DISMATCHINC SIINC DILOOP COMPAREMATCH:LEA DX,MESSAGE1JMP DISPDISMATCH:LEA DX,MESSAGE2DISP: MOV AH,09HINT 21HMOV AH,4CHINT 21HCODE ENDSEND START实验二:编写程序,从键盘输入一串字符,以$或回车结束,将其中的小写字母转变为大写字母,其余字符不做转换,原样输出,结果显示在屏幕上。参考程序:DATA SEGMENTBUF DB 50 DB ? DB 50 DUP(?)INPUTSTRING DB 'PLEASE INPUT A STRING:','$'OUTPUTSTRING DB 'OUTPUTSTRING IS:','$'ENTERSTRING DB 0DH,0AH,'$'DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXLEA DX,INPUTSTRINGMOV AH,09HINT 21HLEA DX,BUFMOV AH,0AHINT 21HLEA DX,ENTERSTRINGMOV AH,09HINT 21H LEA BX,BUFADD BX,2NEXT1:MOV AL,BXINC BXCOMPARE:CMP AL,24H JZ DISP CMP AL,61H JB NEXT1 CMP AL,7AH JA NEXT1 SUB AL,20H MOV BX-1,AL JMP NEXT1DISP:LEA DX,OUTPUTSTRING MOV AH,09H INT 21H LEA DX,BUF+2 MOV AH,09H INT 21H MOV AH,4CH INT 21HCODE ENDSEND START实验三:利用子程序方法编写程序,设有10个无符号数的字节序列,查找该序列中的最大值和最小值,并把结果显示在屏幕上。参考程序1:(针对一位10进制数)STACK SEGMENT STACKDW 256 DUP(?) TOP LABEL WORDSTACK ENDSDATA SEGMENTBUF DB 00H,01H,02H,03H,04HDB 05H,06H,07H,08H,09HCOUNT EQU $-BUFENTERSTRING DB 0DH,0AH,'$'MAXSTRING DB 'THE MAXIMUN NUMBER IS:','$'MINSTRING DB 'THE MINIMUN NUMBER IS:','$'DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKSTART:MOV AX,DATAMOV DS,AXMOV AX,STACKMOV SS,AXLEA SP,TOPMOV SI,OFFSET BUFMOV CX,COUNTCALL BRANCHPUSH AXLEA DX,MAXSTRINGMOV AH,09HINT 21HPOP AXMOV DL,AHADD DL,30HPUSH AXMOV AH,02HINT 21HLEA DX,ENTERSTRINGMOV AH,09HINT 21HLEA DX,MINSTRINGMOV AH,09HINT 21HPOP AXMOV DL,ALADD DL,30HMOV AH,02HINT 21HMOV AH,4CHINT 21HBRANCHPROC NEARJCXZ NEXT4PUSH SIPUSH CXPUSH BXMOV BH,SIMOV BL,BHCLDNEXT1:LODSBCMP AL,BHJBE NEXT2MOV BH,ALJMP NEXT3NEXT2:CMP AL,BLJAE NEXT3MOV BL,ALNEXT3:LOOP NEXT1MOV AX,BXPOP BXPOP CXPOP SINEXT4:RETBRANCHENDPCODE ENDS END START参考程序二:(针对两位十六进制数或无符号数)STACK SEGMENT STACKDW 256 DUP(?) TOP LABEL WORDSTACK ENDSDATA SEGMENTBUF DB 0FFH,55H,33H,44H,54HDB 45H,46H,47H,48H,1AHCOUNT EQU $-BUFENTERSTRING DB 0DH,0AH,'$'MAXSTRING DB 'THE MAXIMUN NUMBER IS:','$'MINSTRING DB 'THE MINIMUN NUMBER IS:','$'DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKSTART:MOV AX,DATAMOV DS,AXMOV AX,STACKMOV SS,AXLEA SP,TOPMOV SI,OFFSET BUFMOV CX,COUNTCALL BRANCHMOV DX,AXPUSH DXLEA DX,MAXSTRINGMOV AH,09HINT 21HPOP DXMOV AL,DHPUSH DXCALL DISPGAO4POP DXMOV AL,DHPUSH DXCALL DISPDI4LEA DX,ENTERSTRINGMOV AH,09HINT 21HLEA DX,MINSTRINGMOV AH,09HINT 21HPOP DXMOV AL,DLPUSH DXCALL DISPGAO4POP DXMOV AL,DLCALL DISPDI4MOV AH,4CHINT 21HBRANCHPROC NEARJCXZ NEXT4PUSH SIPUSH CXPUSH BXMOV BH,SIMOV BL,BHCLDNEXT1:LODSBCMP AL,BHJBE NEXT2MOV BH,ALJMP NEXT3NEXT2:CMP AL,BLJAE NEXT3MOV BL,ALNEXT3:LOOP NEXT1MOV AX,BXPOP BXPOP CXPOP SINEXT4:RETBRANCHENDPDISPDI4PROC NERR ;低四位AND AL,0FHMOV DL,ALCMP DL,9JLE NUM1ADD DL,7NUM1:ADD DL,30HMOV AH,02HINT 21HRETDISPDI4 ENDPDISPGAO4PROC NERR ;高四位SAR AL,4AND AL,0FHMOV DL,ALCMP DL,9JLE NUM2ADD DL,7NUM2:ADD DL,30HMOV AH,02HINT 21HRETDISPGAO4 ENDPCODE ENDS END START实验四:8255交通灯参考程序:MY8255_A EQU 288H ;8255的A口地址MY8255_B EQU 289H ;8255的B口地址MY8255_C EQU 28AH ;8255的C口地址MY8255_MODE EQU 28BH ;8255的控制寄存器地址STACK1 SEGMENT STACK DW 256 DUP(?)STACK1 ENDSDATA SEGMENT LA DB ? ;定义数据变量LB DB ?DATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX MOV DX,MY8255_MODE ;定义8255工作方式 MOV AL,80H ;工作方式0,A口和B口为输出 OUT DX,ALL1: MOV DX,MY8255_A ;写A口发出的数据,1组绿灯亮,2组红灯亮 MOV AL,24H OUT DX,AL CALL DALLY1 MOV CX,05HL2: MOV DX,MY8255_A ;写A口发出的数据,1组黄灯亮,2组红灯亮 MOV AL,44H OUT DX,AL CALL DALLY2 MOV DX,MY8255_A ;写A口发出的数据,1组黄灯灭,2组红灯亮 MOV AL,04H OUT DX,AL CALL DALLY2 LOOP L2L3: MOV DX,MY8255_A ;写A口发出的数据,1组绿灯亮,2组红灯亮 MOV AL,81H OUT DX,AL CALL DALLY1 MOV CX,05HL4: MOV DX,MY8255_A ;写A口发出的数据,1组黄灯亮,2组红灯亮 MOV AL,82H OUT DX,AL CALL DALLY2 MOV DX,MY8255_A ;写A口发出的数据,1组黄灯灭,2组红灯亮 MOV AL,80H OUT DX,AL CALL DALLY2 LOOP L4L5: MOV AH,01H ;判断是否有按键按下,调用功能号1 INT 16H ;ROM BIOS 功能调用 JZ L1 ;无按键则跳回继续循环,有则退出QUIT: MOV AX,4C00H ;结束程序退出; INT 21H ;DOS 系统功能调用DALLY1 PROC NEAR ;软件延时子程序,东西方向红灯亮,南北方向绿灯亮 PUSH CX PUSH DI MOV CX,3FFHY1: MOV DI,9000HX1: DEC DI JNZ X1 LOOP Y1 POP DI POP CX RETDALLY1 ENDPDALLY2 PROC NEAR ;软件延时子程序,黄灯闪烁(即亮与灭)的时间间隔, PUSH CX PUSH DI MOV CX,3FHY2: MOV DI,9000HX2: DEC DI JNZ X2 LOOP Y2 POP DI POP CX RETDALLY2 ENDPCODE ENDS END START参考程序2:流水灯MY8255_A EQU 288H ;8255的A口地址MY8255_B EQU 289H ;8255的B口地址MY8255_C EQU 28AH ;8255的C口地址MY8255_MODE EQU 28BH ;8255的控制寄存器地址STACK1 SEGMENT STACK DW 256 DUP(?)STACK1 ENDSDATA SEGMENT LA DB ? ;定义数据变量DATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX MOV DX,MY8255_MODE ;定义8255工作方式 MOV AL,80H ;工作方式0,A口和B口为输出 OUT DX,AL MOV CX,0FFFFH MOV BL,80HL1: MOV DX,MY8255_A ;写A口发出的数据 MOV AL,BL OUT DX,AL CALL DALLY1 ROR BL,1 LOOP L1QUIT: MOV AX,4C00H ;结束程序退出 INT 21H ;DOS 系统功能调用DALLY1 PROC NEAR ;软件延时子程序,东西方向红灯亮,南北方向绿灯亮 PUSH CX PUSH DI MOV CX,3FHY1: MOV DI,9000HX1: DEC DI JNZ X1 LOOP Y1 POP DI POP CX RETDALLY1 ENDPCODE ENDS END START实验五:8254一赫兹方波输出参考程序:MY8254_COUNT0 EQU 280H ;8254计数器0端口地址MY8254_COUNT1 EQU 281H ;8254计数器1端口地址MY8254_COUNT2 EQU 282H ;8254计数器2端口地址MY8254_MODE EQU 283H ;8254控制寄存器端口地址 STACK1 SEGMENT STACK DW 256 DUP(?)STACK1 ENDSCODE SEGMENT ASSUME CS:CODESTART: MOV DX,MY8254_MODE ;初始化8254工作方式 MOV AL,37H ;计数器0,方式3 OUT DX,AL MOV DX,MY8254_COUNT0 ;装入计数初值 MOV AL,00 ;1000分频 OUT DX,AL MOV AL,10 OUT DX,AL MOV DX,MY8254_MODE ;初始化8254工作方式 MOV AL,77H ;计数器1,方式3 OUT DX,AL MOV DX,MY8254_COUNT1 ;装入计数初值 MOV AL,00 ;1000分频 OUT DX,AL MOV AL,10 OUT DX,AL QUIT: MOV AX,4C00H ;结束程序退出 INT 21H CODE ENDS END START实验六:AD转换(0809)参考程序:CODE SEGMENTASSUME CS:CODESTART: MOV DX,298H ;启动A/D转换器OUT DX,ALMOV CX,0FFFFHDELAY:LOOP DELAYMOV DX,298HIN AL,DXPUSH DXPUSH AXCALL DISPGAO4POP AXPOP DXCALL DISPDI4PUSH DXMOV AH,06HMOV DL,0FFHINT 21HPOP DXJE STARTMOV AH,4CHINT 21HDISPDI4PROC NERR ;低四位AND AL,0FHMOV DL,ALCMP DL,9JLE NUM1ADD DL,7NUM1:ADD DL,30HMOV AH,02HINT 21HRETDISPDI4 ENDPDISPGAO4PROC NERR ;高四位SAR AL,4AND AL,0FHMOV DL,ALCMP DL,9JLE NUM2ADD DL,7NUM2:ADD DL,30HMOV AH,02HINT 21HRETDISPGAO4 ENDPCODE ENDS END START-第 12 页-