1、微机实验报告一、实验目的: 近一步熟悉汇编语言的编辑、宏汇编、链接和运行的基本概念 熟练掌握动态调试程序 TD/DEBUG 的常用指令和窗口功能,学会用TD/DEBUG 调试程序,修改数据和寄存器环境 熟悉掌握汇编语言程序的典型数据结构设计、典型程序控制方法,了解DOS/BIOS 功能调用的基本方法二、实验内容:2-1. 从键盘输入任意字符串后,存入自定义存储单元,判断处理后将字符串中小写字母转换为大写字母(其它字符不变) ,并按原顺序将这些字符在屏幕上显示出来(参考程序 P36) ,并显示字符串“The total number is XXXXX”。实验程序:DATA SEGMENTINPU
2、T DB 100,100 DUP(0)TEN DB 0AHSTRING1 DB 0Dh,0Ah, please input your strings,0Dh,0Ah,$STRING2 DB 0DH,0AH,the total number is:,0DH,0AH,$STRING3 DB 0DH,0AH,the strings after being converted is,0DH,0AH,$DATA ENDSSTACKS SEGMENT PARA stack STACKDB 256 dup(0)STACKS ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:
3、STACKSMAIN PROC FARSTART: MOV AX, DATAMOV DS,AXMOV AX,STACKSMOV SS,AXMOV DX,OFFSET STRING1MOV AH,09HINT 21HMOV DX,OFFSET INPUTMOV AH,0AHINT 21HMOV DX, OFFSET STRING2MOV AH,09HINT 21HMOV AX,WORD PTR INPUT1AND AX,00FFHDIV TENPUSH AXADD AL,30HMOV DL,ALMOV AH,02HINT 21HPOP AXADD AH,30HMOV DL,AHMOV AH,02
4、HINT 21HMOV DX, OFFSET STRING3MOV AH,09HINT 21HCALL CONVERTMOV AH ,4CHINT 21HMAIN ENDPCONVERT PROC NEARXOR CX,CXMOV CL,INPUT1MOV SI,2AGAIN: MOV DL,INPUTSICMP DL,61HJB NEXTCMP DL,7AHJA NEXTSUB DL,20HNEXT: MOV AH,02HINT 21HINC SILOOP AGAINRETCONVERT ENDPCODE ENDSEND START2-2.从键盘输入一个 0255 之间的十进制数,将其转换为
5、 16 进制数,并在屏幕上显示变换前后的数据(参考程序 P38) 。实验程序:DATA SEGMENTRIGHT DB 1INPUT DB 6 ,7 DUP(?)OUTPUT DB 00HTEN DB 0AHSTRING1 DB 0DH,0AH,please input your number,0DH,0AH,$STRING2 DB 0DH,0AH,the number your input is not from 0255,0DH,0AH,$STRING3 DB 0DH,0AH,The number your put is(in H): ,0DH,0AH,$STRING4 DB 0DH,0A
6、H,The number your put is(in D):,0DH,0AH,$DATA ENDSSTACKS SEGMENT STACKDB 256 DUP(0)STACKS ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACKSMAIN PROC FARSTART: MOV AX,DATAMOV DS,AXMOV AX,STACKSMOV SS,AXMOV OUTPUT ,00HMOV DX,OFFSET STRING1MOV AH,09HINT 21HMOV DX,OFFSET INPUTMOV AH,0AH INT 21HMOV RIGHT
7、, 1CALL CHANGECMP RIGHT ,0JZ ERRORMOV DX,OFFSET STRING4MOV AH,09HINT 21HMOV CL,INPUT1MOV SI,2LOOP1: MOV DL,INPUTSIMOV AH,02HINT 21HINC SILOOP LOOP1MOV DX,OFFSET STRING3MOV AH,09HINT 21HMOV DL,OUTPUTPUSH DXMOV CL,4SHR DL,CLCALL DISPPOP DXAND DL,0FHCALL DISPJMP GOERROR: MOV DX,OFFSET STRING2MOV AH, 09
8、HINT 21H GO: MOV AH,4CHINT 21HMAIN ENDPCHANGE PROC NEARCLCXOR AX,AXXOR BX,BXXOR DX,DXMOV CL,INPUT1MOV SI,2AGAIN: MOV BL,INPUTSICMP BL,30HJB ERROR1CMP BL,39HJA ERROR1SUB BL,30HDEC CLCMP CL,0JZ OVERMOV AL,1PUSH CXLOOP2: MUL TENLOOP LOOP2POP CXMUL BLJC ERRORADD OUTPUT,ALJC ERRORINC SIJMP AGAINOVER: ADD
9、 OUTPUT,BLJNC OVER1ERROR1: MOV RIGHT,0OVER1: RETCHANGE ENDPDISP PROC NEARCMP DL,9JBE NUMADD DL,07HNUM: ADD DL,30HMOV AH,02HINT 21HRETDISP ENDPCODE ENDSEND START2-3、从键盘输入 5 个十六进制带符号数(范围为-128+127) ,请将它们按从大到小排序,并将排序前后的数据显示在屏幕上。实验程序:DATA SEGMENTINPUT DB 30 DUP(0)HEX DB 10HAFCMP DB 5 DUP(0)STRING1 DB 0DH
10、,0AH,Please input your numbers:,0DH,0AH,$STRING2 DB 0DH,0AH,The numbers you input are:,0DH,0AH,$STRING3 DB 0DH,0AH,Numbers after being compared is:,0DH,0AH,$DATA ENDSSTACKS SEGMENT STACKDB 256 DUP(0)STACKS ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACKSMAIN PROC FARSTART: MOV AX,DATAMOV DS,AXMOV A
11、X,STACKSMOV SS,AXMOV DX,OFFSET STRING1MOV AH,09HINT 21HMOV DX,OFFSET INPUTMOV AH,0AHINT 21HCALL CHANGEMOV DX,OFFSET STRING2MOV AH,09HINT 21HCALL CONVERTMOV DX,OFFSET STRING3MOV AH,09HINT 21HMOV SI,5MOV CX,4LOOP EXCHANGECHANGE PROC NEARCLCXOR AX,AXXOR BX,BXXOR DX,DXMOV SI,2MOV DI,0AGAIN1: MOV CL,2AGA
12、IN2: MOV BL,INPUTSICMP BL,20HJZ NEXT1CMP BL,48HJZ NEXT2CMP BL,40HJL NUMSUB BL,7HNUM SUB BL,30HDEC CLCMP CL,0JZ OVER1MOV AL,1PUSH CXLOOP1: MUL HEXLOOP LOOP1POP CXMUL BLADD AFCMPDI,ALINC SIJMP AGAIN2OVER1: ADD AFCMPDI,BLCMP DI,4JZ OVERNEXT2: INC SIJMP AGAIN2NEXT1: INC SIINC DIJMP AGAIN1OVER RETCHANGE
13、ENDPCONVERT PROC NEARXOR CX,CXMOV CL,INPUT1MOV SI,2AGAIN: MOV DL,INPUTSICMP DL,61HJB NEXTCMP DL,7AHJA NEXTSUB DL,20HNEXT: MOV AH,02HINT 21HINC SILOOP AGAINRETCONVERT ENDPEXCHANGE PROC NEARPUSH SIPUSH CXMOV AL,AFCMPSICMP AL,AFCMPCLJL LOOP3MOV BL,AFCMPCLMOV AFCMPSI,BLMOV AFCMPCL,ALLOOP3: LOOP LOOP2MOV
14、 AL,AFCMPSIMOV DL,ALMOV CL,4SHR DL,CLCALL CONMOV,DL,ALAND DL,0FCALL CONMOV DL,48HMOV AH,02HINT 21HMOV DL,0HMOV AH,02HINT 21HPOP SIPOP CXDEC CXDEC SIRETEXCHANGE ENDPCON: PROC NEARCMP DL,9JBE MEMADD DL,7MEM: ADD DL,30HMOV AH,02HINT 21HRETCON ENDPCODE ENDSEND START三、实验结果:2-1 的结果2-2 的结果:2-3 的程序已经编译通过,也可
15、以运行,但是无法得到正确的结果四、遇到的问题和解决办法实验 2-1 中所遇到的问题在于如何将十六进制的字母总数转变为十进制并通过显示器显示出来。我开始将 input 存储单元的第二个数以字节的形式取出,然后进行除法运算,但发现编译错误。仔细阅读除法指令的使用规则时发现:除数是八位二进制数时,被除数必须是十六位。于是将被除数以字形式取出在经过相应的转换最终得到正确的结果。实验 2-2 中第一次用 65 运行时并没有错误,但在后续的测试中发现:当输入的十进制数为 300 时,运行结果与实际不符。通过调试发现当在计算输入十进制数最高位的权值时,如果发生进位而进位后的余数无法再次进位时,运行结果将发生错误。因此在循环乘十的语句后面加上语句 JC ERROR,这样运行结果就完全正确了。