【实验题目】简易计算器设计【实验目的】综合测试学生微机接口技术及应用能力,包括系统构思设计、电路设计搭建、软件调试等;结合应用实际,培养学生运用微机技术服务应用、服务实际的能力。
【基本要求】1)利用实验箱上的4x4键盘及6位数码管,实现两个16位宽的非负整数(0~65535)进行+、-、×运算,计算结果限制在范围-65535~65535,超过范围在数码管最低位显示E;2) 16个按键的分配可以自行指定;【扩展要求】1)按基本要求保持输入的范围不变(16位宽),扩展计算结果的范围到用足6位数码管,当计算结果超过-65535~999999时,显示E;2)增加÷的功能,有小数显示;【实验程序】;该程序实现了基本要求及扩展要求的2)DSEG SEGMENTBUFF DB 6 DUP()LED_7 DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39 H,5EH,79H,71H,00H,40HPOSITION DB 0DFH,0EFH,0F7H,0FBH,0FDH,0FEHUNIT10 DW 10000,1000,100,10,1NEWNUM DB 0COUNT DB 0FLAG DB 0 ;是否有键按下的标志NEGTI DB 0 ;是否为负数的标志NUM DW 0NUM1 DW 0NUM2 DW 0TAG DB 0 ;运算种类标志POINT DB 0 ;除法结果添加小数点标志RESULT DW 0DSEG ENDSCSEG SEGMENTASSUME DS:DSEG,CS:CSEGSTART:MOV AX,DSEGMOV DS,AXMOV DX,300CH ;8255初始化MOV AL,81HOUT DX,ALLEA SI,BUFFMOV CX,6 NEXT:MOV BYTE PTR[SI],16INC SILOOP NEXTCALL SHOW ;将显示缓冲区中内容在LED上一次显示出来MOV COUNT,0 ;记按下了几位数NEXT2:CALL SHOWCALL SCAN ;判断是否有按键按下CMP FLAG,1JZ OKJMP NEXT2OK:MOV FLAG,0MOV POINT,0MOV DX,3000H ;判断是哪一个键被按下MOV AL,0FFHOUT DX,ALMOV CH,-1 ;CH用于保存当前被扫描的列号MOV CL,07FHXL:ROL CL,1INC CHMOV DX,3000HMOV AL,CLOUT DX,ALMOV DX,3008HIN AL,DXAND AL,0FHCMP AL,0FHJZ XL ;选中下一列被扫描CMP AL,0EHJNZ FOURMOV CL,0 ;CL保存行号JMP FREEFOUR:CMP AL,0DHJNZ BAMOV CL,4JMP FREEBA:CMP AL,0BHJNZ SHIERMOV CL,8JMP FREESHIER:CMP AL,07HJNZ XLMOV CL,12FREE:ADD CH,CL ;行列值相加为按键代表的值CMP CH,9JBE SHUZICMP CH,12 ;加法JZ JIAFACMP CH,13 ;减法JZ JIANFACMP CH,14 ;乘法JZ CHENGFACMP CH,15 ;除法JZ CHUFACMP CH,11 ;等号时进行运算JZ YUNSUANCMP CH,10 ;此键清屏重新输入JZ CLEARSHUZI:INC COUNTMOV NEWNUM,CHCALL COPY ;将新输入的按键值送入显示缓冲区的最末位MOV DX,3000H ;将LED关显示MOV AL,0FFHOUT DX,ALCALL DELAY2JMP NEXT2 JIAFA:MOV TAG,1 ;置加法标志CALL TO_DEC ;将输入的数转化为十进制数保存MOV AX,NUMMOV NUM1,AXJMP START ;继续输入第二个按键数JIANFA:MOV TAG,2CALL TO_DECMOV AX,NUMMOV NUM1,AXJMP STARTCHENGFA:MOV TAG,3CALL TO_DECMOV AX,NUMMOV NUM1,AXJMP STARTCHUFA:MOV TAG,4CALL TO_DECMOV AX,NUMMOV NUM1,AXJMP STARTCLEAR:JMP STARTYUNSUAN:CALL TO_DEC ;将第二次输入的数转化为十进制数保存MOV AX,NUMMOV NUM2,AXCMP TAG,1JZ SJIAFCMP TAG,2JZ SJIANFCMP TAG,3JZ SCHENGFCMP TAG,4JZ SCHUFYEAH:CALL CHULI ;将结果中零的位置16关显示MOV TAG,0MOV NEGTI,0CALL SHOWJMP NEXT2SJIAF:CALL JIAJMP YEAHSJIANF:CALL JIANJMP YEAHSCHENGF:CALL CHENGJMP YEAHSCHUF:CALL CHUJMP YEAHMOV AH,4CHINT 21HJIA PROC NEARPUSH AXPUSH CXPUSH SIMOV AX,NUM1ADD AX,NUM2JC YC1 ;溢出MOV RESULT,AXCALL TO_SHOWSHUJMP OVER1YC1:LEA SI,BUFFMOV BYTE PTR[SI],14INC SIMOV CX,5SS0:MOV BYTE PTR[SI],16INC SILOOP SS0OVER1:POP SIPOP CXPOP AXRETJIA ENDPJIAN PROC NEARPUSH AXPUSH CXPUSH SIMOV AX,NUM1CMP AX,NUM2JA POSITIVEMOV NEGTI,1 ;结果为负数MOV AX,NUM2SUB AX,NUM1JC YC2JMP OV POSITIVE:MOV AX,NUM1 SUB AX,NUM2JC YC2OV:MOV RESULT,AX CALL TO_SHOWSHU JMP OVER2YC2:LEA SI,BUFFMOV BYTE PTR[SI],14 INC SIMOV CX,5SS2:MOV BYTE PTR[SI],16 INC SILOOP SS2OVER2:POP SIPOP CXPOP AXRETJIAN ENDP CHENG PROC NEAR PUSH AXPUSH CXPUSH SIMOV AX,NUM1 MUL NUM2JC YC3MOV RESULT,AX CALL TO_SHOWSHU JMP OVER3YC3:LEA SI,BUFFMOV BYTE PTR[SI],14 INC SIMOV CX,5SS3:MOV BYTE PTR[SI],16 INC SILOOP SS3OVER3:POP SIPOP CXPOP AXRETCHENG ENDPCHU PROC NEAR PUSH AXPUSH CXPUSH DXPUSH SIXOR DX,DXMOV AX,NUM1DIV NUM2PUSH DXMOV RESULT,AX CALL TO_SHOWSHU MOV POINT,1LEA SI,BUFFADD SI,5MOV CX,5PEA:MOV AL,[SI-1]MOV [SI],ALDEC SILOOP PEAPOP DXMOV AX,10MUL DXXOR DX,DXDIV NUM2MOV [SI],ALPOP SIPOP DXPOP CXPOP AXRETCHU ENDPCHULI PROC NEAR PUSH SIPUSH CXLEA SI,BUFFADD SI,5XX:CMP BYTE PTR[SI],0 JNZ NOZEROMOV BYTE PTR[SI],16 DEC SIJMP XX NOZERO:CMP NEGTI,1JNZ ZHENGINC SIMOV BYTE PTR[SI],17 ZHENG:POP CXPOP SICHULI ENDPTO_DEC PROC NEAR PUSH SIPUSH AXPUSH BXPUSH CXLEA SI,BUFFMOV AL,COUNTXOR AH,AHADD SI,AXDEC SIXOR AX,AXXOR CH,CHMOV CL,COUNT AGAIN:ADD AX,AXMOV BX,AXADD AX,AXADD AX,AXADD AX,BXMOV BH,0MOV BL,[SI]ADD AX,BXDEC SILOOP AGAINMOV NUM,AXPOP CXPOP BXPOP AXPOP SIRETTO_DEC ENDPTO_SHOWSHU PROC NEAR PUSH SIPUSH DIPUSH AXPUSH BXPUSH CXLEA DI,BUFFADD DI,5LEA SI,UNIT10MOV AX,RESULTMOV BYTE PTR[DI],0 DEC DILOP0:XOR CL,CLMOV BX,[SI]LOP1:SUB AX,BXJB LOP3INC CLJMP LOP1LOP3:ADD AX,BXMOV [DI],CLINC SIINC SIDEC DICMP BX,1JNZ LOP0POP CXPOP BXPOP AXPOP DIPOP SIRETTO_SHOWSHU ENDPSHOW PROC NEARPUSH AXPUSH BXPUSH CXPUSH DXPUSH SIPUSH DICMP POINT,1 ;是否需添加小数点JNZ NOPOINTMOV CH,0FFHAA3:LEA SI,BUFFLEA DI,POSITIONMOV AL,[SI]LEA BX,LED_7XLATMOV DX,3004HOUT DX,ALMOV DX,3000HMOV AL,[DI]OUT DX,ALCALL DELAY ;延时,使一位稳定显示INC SIINC DIMOV AL,[SI]LEA BX,LED_7 XLATOR AL,80H ;填小数点MOV DX,3004HOUT DX,ALMOV DX,3000HMOV AL,[DI]OUT DX,ALCALL DELAY ;延时,使一位稳定显示INC SIINC DIMOV CL,4AA2:MOV AL,[SI]LEA BX,LED_7XLATMOV DX,3004HOUT DX,ALMOV DX,3000HMOV AL,[DI]OUT DX,ALCALL DELAY ;延时,使一位稳定显示INC SIINC DIDEC CHJZ REALSTOPDEC CLJNZ AA2JMP AA3NOPOINT:MOV CH,0FFHAA1:LEA SI,BUFFLEA DI,POSITIONMOV CL,6AA:MOV AL,[SI]LEA BX,LED_7XLATMOV DX,3004HOUT DX,ALMOV DX,3000HMOV AL,[DI]OUT DX,ALCALL DELAY ;延时,使一位稳定显示INC SIINC DIDEC CHJZ REALSTOPDEC CLJNZ AAJMP AA1 REALSTOP:POP DIPOP SIPOP DXPOP CXPOP BXPOP AXRETSHOW ENDP DELAY PROC NEAR PUSH BXPUSH CXMOV BX,3FFH DEL1:MOV CX,0FFFH DEL2:LOOP DEL2DEC BXJNZ DEL1POP CXPOP BXRETDELAY ENDP DELAY2 PROC NEAR PUSH BXPUSH CXMOV BX,3FHDEL3:MOV CX,0FFH DEL4:LOOP DEL4DEC BXJNZ DEL3POP CXPOP BXRETDELAY2 ENDP SCAN PROC NEARPUSH AXPUSH DXKS:MOV DX,3000HMOV AL,0OUT DX,ALMOV DX,3008HIN AL,DXAND AL,0FH ;屏蔽高四位CMP AL,0FHJZ JIESHUMOV FLAG,1JIESHU:POP DXPOP AXRETSCAN ENDPCOPY PROC NEARPUSH SIPUSH CXPUSH AXMOV CX,5LEA SI,BUFFADD SI,5NEXT1:MOV AL,[SI-1]MOV [SI],ALDEC SILOOP NEXT1MOV AL,NEWNUMMOV [SI],ALPOP AXPOP CXPOP SIRETCOPY ENDPCSEG ENDSEND START。