1、微机原理大作业汇编语言程序设计综合实验学校: * 学院: * 班级: * 姓名: * 学号: * 指导教师: * 一、实验目的1.通过上机编程,熟悉汇编语言程序设计的流程。2.通过编程实践,掌握常用的汇编程序设计方法与技巧。3.学会汇编语言简单菜单程序的设计。二、实验仪器 电脑一台三、实验内容利用汇编语言设计一个菜单程序,完成以下功能:(1)小写字母变大写字母(2)找最大值(3)递增排序(4)时间设置与显示(5)结束程序运行四、程序代码STACK SEGMENT STACK STACK DW 100H DUP(?)TOP LABEL WORDSTACK ENDSDATA SEGMENT STR
2、ING1 DB 1.Lowercase to Uppercase,0DH,0AH,$ STRING2 DB 2.Find the Maximum,0DH,0AH,$ STRING3 DB 3.Sort (Ascending Order),0DH,0AH,$ STRING4 DB 4.Time Settings and Display,0DH,0AH,$ STRING5 DB 5.Exit,0DH,0AH,$ STRING6 DB Please Choose:,$ STRING7 DB Please input the string:,0DH,0AH,$ STRING8 DB The maxim
3、um is ,$ STRING9 DB Please input the numbers:,0DH,0AH,$ STRINGA DB Please set the time (HH:MM:SS),$ STRDEC DB DEC:,$ STRHEX DB HEX:,$ TABLE DW G1,G2,G3,G4,G5 ;转移地址表 KEYLEN DB 20H,? KEYBUF DB 21H DUP(?)DATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACKSETCUR MACRO ROW,COLUMN,PAGE ;设置光标宏指令
4、MOV AH,2 ;设置光标位置 MOV DH,ROW ;行 MOV DL,COLUMN ;列 MOV BH,PAGE ;页 INT 10H ENDM DISSTR MACRO STROFFSET ;显示字符串宏指令 MOV AH,9 LEA DX,STROFFSET INT 21H ENDM DISHMS MACRO REG ;显示时、分或秒宏指令 MOV AL,REG MOV AH,0 MOV BL,10 DIV BL MOV DL,AL MOV BH,AH OR DL,30H MOV AH,2 INT 21H MOV DL,BH OR DL,30H MOV AH,2 INT 21H EN
5、DM START: MOV AX,DATA ;主程序初始化 MOV DS,AX MOV ES,AX MOV AX,STACK MOV SS,AX LEA SP,TOP CALL DISMENU ;显示菜单 CHOOSE: SETCUR 14,20,0 MOV AH,1 ;输入选项 INT 21H CMP AL,1 JB CHOOSE CMP AL,5 JA CHOOSE AND AL,0FH DEC AL SHL AL,1 CBW LEA BX,TABLE ADD BX,AX JMP WORD PTRBX EXIT: MOV AH,4CH ;终止进程 INT 21H CLEAR MACRO ;
6、清屏宏指令 MOV AH,0 ;设置显示方式 MOV AL,1 ;4025彩色方式 INT 10H ENDM G1: CLEAR SETCUR 0,0,0 DISSTR STRING1 SETCUR 1,0,0 DISSTR STRING7 MOV AH,0AH ;输入字符串 MOV DX,OFFSET KEYLEN INT 21H MOV CL,KEYLEN+1 MOV CH,0 MOV SI,0L11: MOV AL,KEYBUFSI CMP AL,a JB L12 CMP AL,z JA L12 AND KEYBUFSI,5FH L12: INC SI LOOP L11 MOV KEYB
7、UFSI,$ SETCUR 3,0,0 DISSTR KEYBUF L13: MOV AH,6 ;直接控制台I/O MOV DL,0FFH INT 21H JZ L13 CMP AL,1BH ;判断是否按下ESC键 JNZ G1 JMP START G2: CLEAR SETCUR 0,0,0 DISSTR STRING2 SETCUR 1,0,0 DISSTR STRING7 MOV AH,0AH ;输入字符串 MOV DX,OFFSET KEYLEN INT 21H MOV CL,KEYLEN+1 MOV CH,0 MOV DL,KEYBUF MOV SI,1 L21: CMP KEYBU
8、FSI,DL JBE L22 MOV DL,KEYBUFSI L22: INC SI CMP SI,CX JNZ L21 PUSH DX SETCUR 3,0,0 DISSTR STRING8 POP DX MOV AH,2 ;显示结果 INT 21H MOV AH,2 ;显示结果 MOV DL,. INT 21H L23: MOV AH,6 ;直接控制台I/O MOV DL,0FFH INT 21H JZ L23 CMP AL,1BH ;判断是否按下ESC键 JNZ G2 JMP START G3: CLEAR SETCUR 0,0,0 DISSTR STRING3 SETCUR 1,0,0
9、 DISSTR STRING9 MOV DH,10 MOV BH,0 ;空格标志 MOV DI,0 L36: MOV DL,0 L33: MOV AH,1 INT 21H CMP AL,0DH ;判断是否按下回车键 JZ L31 CMP AL,20H ;判断是否按下空格键 JZ L32 MOV BH,0 AND AL,0FH MOV BL,AL MOV AL,DL MUL DH ADD AL,BL MOV DL,AL JMP L33L32: CMP BH,0 JNZ L34 MOV KEYBUFDI,DL INC DI L34: MOV BH,1 JMP L36L31: CMP BH,0 JN
10、Z L35 MOV KEYBUFDI,DL INC DIL35: CALL SORT SETCUR 3,0,0 DISSTR STRDEC MOV SI,0 L3C: MOV AL,KEYBUFSI MOV CL,0 ;位数 CBW CMP AX,0 JZ L37 MOV BL,10L39: DIV BL MOV DL,AH MOV AH,0 OR DL,30H MOV DH,0 PUSH DX INC CL CMP AX,0 JNZ L39 MOV CH,0L3A: POP DX MOV AH,2 INT 21H LOOP L3A JMP L3BL37: MOV AH,2 MOV DL,0
11、INT 21HL3B: MOV AH,2 MOV DL,20H INT 21H INC SI CMP SI,DI JNZ L3C SETCUR 4,0,0 DISSTR STRHEX MOV SI,0 L3D: MOV DL,KEYBUFSI MOV CL,4 SHR DL,CL CMP DL,10 JB L3E ADD DL,7L3E: ADD DL,30H MOV AH,2 INT 21H MOV DL,KEYBUFSI AND DL,0FH CMP DL,10 JB L3F ADD DL,7L3F: ADD DL,30H MOV AH,2 INT 21H MOV AH,2 MOV DL,
12、20H INT 21H INC SI CMP SI,DI JNZ L3D L38: MOV AH,6 ;直接控制台I/O MOV DL,0FFH INT 21H JZ L38 CMP AL,1BH ;判断是否按下ESC键 JNZ G3 JMP START G4: CLEAR SETCUR 0,0,0 DISSTR STRING4 SETCUR 2,0,0 DISSTR STRINGA MOV AH,0AH ;输入时间字符串 MOV DX,OFFSET KEYLEN INT 21H CMP KEYLEN+1,8 JNZ G4 MOV BL,10 MOV AL,KEYBUF AND AL,0FH
13、MOV AH,0 MUL BL MOV CH,KEYBUF+1 AND CH,0FH ADD AL,CH MOV CH,AL ;设置“时” MOV AL,KEYBUF+3 AND AL,0FH MOV AH,0 MUL BL MOV CL,KEYBUF+4 AND CL,0FH ADD AL,CL MOV CL,AL ;设置“分” MOV AL,KEYBUF+6 AND AL,0FH MOV AH,0 MUL BL MOV DH,KEYBUF+7 AND DH,0FH ADD AL,DH MOV DH,AL ;设置“秒” MOV DL,0 ;设置“百分之一秒” MOV AH,2DH INT 2
14、1H ;设置时间 CMP AL,0 JNZ G4L41: SETCUR 0,32,0 MOV AH,2CH INT 21H PUSH DX DISHMS CH ;显示“时” MOV AH,2 MOV DL,: INT 21H DISHMS CL ;显示“分” MOV AH,2 MOV DL,: INT 21H POP DX DISHMS DH ;显示“秒” MOV AH,1 MOV CX,2000H INT 10H MOV AH,6 ;直接控制台I/O MOV DL,0FFH INT 21H JZ L41 CMP AL,1BH ;判断是否按下ESC键 JNZ G4 JMP START G5:
15、JMP EXIT DISMENU PROC NEAR ;显示菜单子程序 CLEAR SETCUR 4,6,0 DISSTR STRING1 SETCUR 6,6,0 DISSTR STRING2 SETCUR 8,6,0 DISSTR STRING3 SETCUR 10,6,0 DISSTR STRING4 SETCUR 12,6,0 DISSTR STRING5 SETCUR 14,6,0 DISSTR STRING6 RET DISMENU ENDP SORT PROC PUSH DI DEC DI CMP DI,0 JZ DONE MOV AX,DI MOV CH,ALN2: MOV C
16、L,CH LEA SI,KEYBUF MOV BL,0 ;交换标志N1: MOV AL,SI CMP AL,SI+1 JBE NOCHG XCHG AL,SI+1 MOV SI,AL MOV BL,1NOCHG: INC SI DEC CL JNZ N1 CMP BL,0 JZ DONE DEC CH JNZ N2DONE: POP DI RETSORT ENDPCODE ENDS END START五、运行结果1.主菜单2.完成功能(1)小写字母变大写字母(2)找最大值(3)递增排序(4)时间设置与显示(5)结束程序运行六、实验总结通过本次实验加深理解了汇编语言的指令含义与其中的基本概念;通过上机编程,熟悉汇编语言程序设计的流程,掌握常用的汇编程序设计方法与技巧,学会汇编语言简单菜单程序的设计。同时,通过上机编程,复习巩固了所学汇编程序设计知识,能够应用汇编语言解决一些实际问题。在本次实验中也遇到了程序设计方面的问题,通过查阅相关资料解决了这些问题。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1