《汇编语言设计课程设计指导书.doc》由会员分享,可在线阅读,更多相关《汇编语言设计课程设计指导书.doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、汇编语言程序设计课程设计指导书一、课程设计的目的本课程设计是在学完教学大纲规定的全部内容、完成所有实践环节的基础上,旨在深化学生学习的汇编语言课程基本知识,进一步掌握汇编语言程序设计方法,提高分析问题、解决问题的综合应用能力。二、课程设计内容(1)课题:磁盘文件管理系统要求:功能菜单的编制;向磁盘文件中写入信息;从磁盘文件中读出信息并显示。参考程序:data segment menu db 0dh,0ah, *,0dh,0ahdb * menu *,0dh,0ahdb *-*,0dh,0ahdb * 1.Create file *,0dh,0ahdb * 2.Write to file *,0
2、dh,0ahdb * 3.Read file *,0dh,0ahdb * 4.Quit *,0dh,0ahdb *-*,0dh,0ahdb * Choice(1-4) *,0dh,0ahdb *,0dh,0ah,$ pathname db D:IBM PC.TXT,00handle dw ? buffer1 db 60,0,60 dup(?) buffer2 db 60,0,60 dup(?)huanhang db ,0dh,0ah,$chose db 0dh,0ah,Please enter the digital from 1-4!,0dh,0ah,$ entery db 0dh,0ah,
3、Enter what you want to write to the file!(The length of the strings is under 60),0dh,0ah,$ str_ok1 db 0dh,0ah,Create !,0dh,0ah,$ str_ok2 db 0dh,0ah,Wtite to !,0dh,0ah,$ str_ok3 db 0dh,0ah,Read from !,0dh,0ah,$str_error1 db Create !$str_error2 db Open !$str_error3 db Write to !$str_error4 db Read !$s
4、tr_error5 db Exit from !$data endscode segmentassume cs:code,ds:datamain proc farstart:mov ax,datamov ds,axmov ax,0600hcall mecall choiceret main endpme proc nearmov ah,9lea dx,menuint 21hme endpchoice proc nearmov ah,1int 21hcmp al,31hje next1cmp al,32hje next2cmp al,33hje next3cmp al,34hje next4jm
5、p backnext1:call creathnext2:call entrynext3:mov ah,9lea dx,huanhangint 21hcall readnext4:mov ax,4c00hint 21hback:mov ah,9lea dx,choseint 21hcall meretchoice endpcreath proc nearmov ah,3chlea dx,pathnamemov cx,0int 21hjc error1mov handle,ax jmp exiterror1:mov ah,9lea dx,str_error1int 21h jmp exit1ex
6、it:mov ah,9lea dx,str_ok1int 21hexit1:call choicecreath endpentry proc nearmov ah,9 lea dx,enteryint 21hlea dx,buffer1mov ah,0ahint 21hsub ch,chmov cl,buffer1+1add dx,2call writh retentry endpwrith proc nearmov ah,3dh lea dx,pathnamemov al,1int 21hjc error2mov handle,axmov ah,40h lea dx,buffer1+2mov
7、 bx,handle mov cx,60int 21hjc error3mov ah,3ehmov bx,handleint 21hjc error4 jmp back1error2:mov ah,9lea dx,str_error2int 21h jmp exit2error3:mov ah,9lea dx,str_error4int 21h jmp exit2error4:mov ah,9lea dx,str_error5int 21h jmp exit2back1:mov ah,9lea dx,str_ok2int 21hexit2:call choicewrith endpread p
8、roc nearmov ah,3dh lea dx,pathnamemov al,0int 21hjc error5mov handle,ax mov ah,3fhlea dx,buffer2mov bx,handle mov cx,60int 21hjc error6mov ah,9 lea dx,buffer2int 21hjc error6mov ah,3ehmov bx,handleint 21hjc error7jmp back2error5:mov ah,9lea dx,str_error2int 21h jmp exit3error6:mov ah,9lea dx,str_err
9、or4int 21h jmp exit3error7:mov ah,9lea dx,str_error5int 21h jmp exit3back2:mov ah,9lea dx,str_ok3int 21hexit3:call choiceread endpcode ends end startend main(2)课题:实现加减乘除四则运算的计算器要求:能实现加、减、乘、除的计算;该程序接受的是16进制数;执行时,需在文件名后直接跟上计算表达式,如在命令提示符下执行结果如下:c:tasmjs 3+25参考程序:B_P EQU BYTE PTRW_P EQU WORD PTRD_P EQU
10、DWORD PTRCODE SEGMENTASSUME CS:CODE,DS:CODE ORG 100H;主程序开始NEWSTAR: JMP STAR EVENNUM1 DW 0,0NUM2 DW 0,0NUM3 DW 0,0JGV4 DW 0,0YSF LABEL WORDYSF1 DB 0YSF2 DB 0JUV DB 0UV DB 0;使DS:SI指向第一有效字符OVERS LABEL NEAR CLD PUSH AXOVERS1: LODSB CMP AL, JZ OVERS1 CMP AL,9 JZ OVERS1 DEC SI CMP AL,13 POP AX RET;输出一个制表符
11、TAB LABEL NEAR MOV AL,9 JMP SHORT DISP;输出一个回车换行符CRLF LABEL NEAR MOV AL,13 CALL DISP MOV AL,10;显示一个字符DISP LABEL NEAR PUSH AX PUSH DX MOV AH,2 MOV DL,AL INT 21H POP DX POP AX RET;检查是否为运算符ISYSF LABEL NEAR CLD LODSB CALL ISJJ JZ ISYSF1 CALL ISII JZ ISYSF1 DEC SIISYSF1: RET;检查是否是加减运算ISJJ LABEL NEAR CMP A
12、L,+ JZ ISYSF1 CMP AL,- RET;检查是否为乘除运算ISII LABEL NEAR CMP AL,* JZ ISYSF1 CMP AL,/ JZ ISYSF1 CMP AL, RET;数据输出;CX=10 十进制;CX=16 十六进制DOUT LABEL NEAR PUSH AX PUSH BX PUSH DX PUSH BP XOR BP,BPDOUT1: INC BP PUSH AX MOV AX,DX XOR DX,DX DIV CX MOV BX,AX POP AX DIV CX PUSH DX MOV DX,BX OR BX,AX JNZ DOUT1DOUT2:
13、POP AX ADD AL,0 CMP AL,9 JBE DOUT3 ADD AL,A-9-1DOUT3: CALL DISP DEC BP JNZ DOUT2 POP BP POP DX POP BX POP AX RET;输入数据在DX:AX中返回;CX=0 数据为10进制;CX#0 数据为16进制DATE LABEL NEAR PUSH BX PUSH BP PUSH DI XOR AX,AX XOR DX,DXDATE1: MOV DI,AX LODSB CMP AL,0 JB DATE7 CMP AL,9 JA DATE6DATE2: AND AX,0FH SHL DI,1 RCL
14、DX,1 MOV BX,DI MOV BP,DX SHL DI,1 RCL DX,1 SHL DI,1 RCL DX,1 JCXZ DATE3 SHL DI,1 RCL DX,1 Jmp short DATE4DATE3: ADD DI,BX ADC DX,BPDATE4: ADD AX,DI ADC DX,0 JMP DATE1DATE5: ADD AL,9 JMP DATE2DATE6: JCXZ DATE7 CMP AL,A JB DATE7 CMP AL,F JBE DATE5 CMP AL,a JB DATE7 CMP AL,f JBE DATE5DATE7: MOV AX,DI D
15、EC SI OR DI,DX POP DI POP BP POP BX RET;数据1及数据2根据YSF1进行加减运算JSJJ LABEL NEAR MOV AX,NUM2 MOV DX,NUM2+2 CMP YSF1,+ JZ JSJJ1 SUB NUM1,AX SBB NUM1+2,DX JMP SHORT JSJJ2JSJJ1: ADD NUM1,AX ADC NUM1+2,DXJSJJ2: RET;数据1及数据2根据YSF1进行乘除运算JSII1 LABEL NEAR MOV BX,OFFSET NUM1 JMP SHORT JSII2_1;数据2及数据3根据YSF2进行乘除运算JSI
16、I2 LABEL NEAR MOV BX,OFFSET NUM2JSII2_1: DB 66H MOV AX,BX DB 66H MOV CX,BX+4 CMP YSF2,* JNZ JSII2_2 DB 66H IMUL CX JMP SHORT JSII2_3JSII2_2: DB 66H CWD DB 66H IDIV CX CMP YSF2,/ JZ JSII2_3 DB 66H XCHG DX,AXJSII2_3: DB 66H MOV BX,AX RET;显示结果XUJG LABEL NEAR MOV AX,JGV4 MOV DX,JGV4+2 MOV CX,10 CMP UV,1
17、0 JZ XUJG0 MOV CX,16XUJG0: TEST DX,8000H JZ XUJG1 CMP UV,10 JZ XUJG2 CALL DOUTXUJG2: NOT AX NOT DX ADD AX,1 ADC DX,0 PUSH AX CMP UV,10 JZ XUJG3 MOV AL, CALL DISP MOV AL,( CALL DISPXUJG3: MOV AL,- CALL DISP POP AX CMP UV,10 JZ XUJG1 CALL DOUT MOV AL,) CALL DISP RETXUJG1: CALL DOUT RET;计算结果放入DX:AX中JSJ
18、G LABEL NEAR CALL JSJJ MOV AX,NUM1 MOV DX,NUM1+2 RET;从DS:SI处取一个数据LOADATE LABEL NEAR LODSB CMP AL,( JZ LOADATE1 DEC SI PUSH CX XOR CX,CX CMP UV,10 JZ LOADATE0 INC CX ;取16进制数LOADATE0: CALL DATE ;取数据放入DX:AX中 POP CX RETLOADATE1: PUSH NUM1 ;保存数据1数据2及运算符 PUSH NUM1+2 PUSH NUM2 PUSH NUM2+2 PUSH YSF INC JUV
19、MOV JGV4,0 ;结果值清零 MOV JGV4+2,0;进行四则运算SZYS LABEL NEAR CALL ISYSF ;首字符是运算符? JZ SZYS2 CALL LOADATE ;不是,取数并保存 MOV NUM1,AX MOV NUM1+2,DXSZYS1: XOR AX,AX ;数据2清零 MOV NUM2,AX MOV NUM2+2,AX CALL ISYSF ;下个是运算符? JZ SZYS3 JNZ SZYS6SZYS2: PUSH AX MOV AX,JGV4 ;将结果作为数据1 MOV NUM1,AX MOV AX,JGV4+2 MOV NUM1+2,AX POP
20、AXSZYS3: MOV YSF1,AL MOV YSF2,AL CALL ISJJ ;是加减运算转 JZ SZYS4 CALL LOADATE ;取数据2 MOV NUM2,AX MOV NUM2+2,DX CALL JSII1 ;数据1及数据2根据YSF1进行乘除运算 JMP SZYS1 ; 结果保存在数据1中SZYS4: CALL LOADATE ;取数据2并保存 MOV NUM2,AX MOV NUM2+2,DXSZYS4_1: CALL ISYSF JNZ SZYS6 CALL ISJJ ;运算符2是加减运算? JNZ SZYS5 ;不是转 PUSH AX CALL JSJJ ;数据
21、1及数据2根据YSF1进行加减运算 POP AX ; 结果保存在数据1中 MOV YSF1,AL ;保存新的运算符 JMP SZYS4SZYS5: MOV YSF2,AL ;保存运算符2 CALL LOADATE ;取数据3 MOV NUM3,AX MOV NUM3+2,DX CALL JSII2 ;数据2及数据3根据YSF2进行乘除运算 JMP SZYS4_1 ; 结果保存在数据2中SZYS6: MOV CL,AL CMP AL,13 JNZ SZYS9SZYS7: CALL JSJG CMP JUV,0 JZ SZYS8 DEC JUV POP YSF POP NUM2+2 POP NUM
22、2 POP NUM1+2 POP NUM1 RETSZYS8: CMP CL,) JZ SZYS10 MOV JGV4,AX MOV JGV4+2,DX JNZ SZYS12SZYS9: CMP AL,) JNZ SZYS11 INC SI JMP SZYS7SZYS10: MOV NUM1,AX MOV NUM1+2,DX JMP SZYS1SZYS11: STC RETSZYS12: CLC RET;数制处理UVIL LABEL NEAR PUSH SIUVIL1: LODSB CMP AL, JZ UVIL2 CMP AL,9 JZ UVIL2 CMP AL,13 JZ UVIL4 JN
23、Z UVIL1UVIL2: MOV BX,SI CALL OVERS JZ UVIL3 LODSW CALL OVERS POP SI JNZ SZYS11 CMP AX,01 JNZ SZYS11 PUSH SI MOV UV,10UVIL3: MOV AL,13 MOV BX-1,ALUVIL4: POP SI CLC RET;预置结果YVJG LABEL NEAR MOV AH,52H INT 21H MOV AX,ES:BX-2 MOV DS,AX MOV AX,DS:0CH MOV CS:JGV4,AX MOV AX,DS:0EH MOV CS:JGV4+2,AX PUSH CS P
24、OP DS PUSH CS POP ES RET;保存结果BCJG LABEL NEAR MOV AH,52H INT 21H MOV AX,ES:BX-2 MOV DS,AX MOV AX,CS:JGV4 MOV DS:0CH,AX MOV AX,CS:JGV4+2 MOV DS:0EH,AX PUSH CS POP DS PUSH CS POP ES RETSTAR: MOV SI,81H CLD CALL OVERS JNZ STAR1STAR0: MOV DX,OFFSET MESS1 JMP STAR4STAR1: CALL YVJG CALL UVIL JB STAR0 MOV S
25、AVESP,SP CALL SZYS MOV SP,SAVESP MOV DX,OFFSET MESS2 JB STAR4 CALL CRLF CALL XUJG CALL BCJG MOV DX,OFFSET MESS3STAR4: MOV AH,9 INT 21H INT 20HSAVESP DW 0MESS1 DB 13,10, Syntax:,13,10 DB JS 10,13,10,$MESS2 DB Error in expression !$MESS3 DB 13,10,$CODE ENDS END NEWSTAR(3)课题:代码转换程序要求:功能菜单的编制;小写字母向大写字母的
26、转换;大写字母向小写字母的转换;二进制数向十六进制数的转换;十六进制数向二进制数的转换;十六进制数向十进制数的转换。参考程序:public info1,info2,bufa,bufb,buf,main,info0,info3extrn change1:far,change2:far,change3:far,change4:fardata segmentinfo0 db 0ah,0dh,this is the change of letter to leter:$ info1 db 0ah,0dh,please input string:$info2 db 0ah,0dh,output stri
27、ng:$bufa db 81 db ? db 80 dup (?)bufb db 80 dup (?)info3 db 0ah,0dh,this is the change of digital to digital:,0ah,0dh,$buf db 0dh,0ah,the number is:01111b,0ah,0dh,the result is:$data endsstack segment stack db 200 dup (?)stack endscode segmentmain proc far assume ds:data,cs:code,ss:stack mov ax,data
28、 mov ds,axdisp macro m lea dx,m mov ah,9 int 21h endm call change1 call change2 disp info3 disp buf call change3 call change4 retmain endpcode ends end extrn info1:byte,info2:byte,bufa:byte,bufb:byte,info0:bytepublic change1code segment assume cs:codelowtohigh proc near cmp al,a jb stop cmp al,z ja
29、stop sub al,20hstop :retlowtohigh endpchange1 proc far lea dx,info0 mov ah,9 int 21h lea dx,info1 mov ah,9 int 21h lea dx,bufa mov ah,10 int 21h lea si,bufa+1 lea di,bufb mov ch,0 mov cl,si add si,1next:mov al,si call lowtohigh mov di,al inc si inc di loop next mov byte ptr di,$ lea dx,info2 mov ah,
30、9 int 21h lea dx,bufb mov ah,9 int 21h retchange1 endp code ends end extrn info1:byte,info2:byte,bufa:byte,bufb:bytepublic change2code segment assume cs:codehightolow proc near cmp al,A jb stop cmp al,Z ja stop add al,20hstop:rethightolow endpchange2 proc far lea dx,info1 mov ah,9 int 21h lea dx,buf
31、a mov ah,10 int 21h lea si,bufa+1 lea di,bufb mov ch,0 mov cl,si inc sinext:mov al,si call hightolow mov di,al inc si inc di loop next mov byte ptr di ,$ lea dx,info2 mov ah,9 int 21h lea dx,bufb mov ah,9 int 21h retchange2 endp code ends endextrn buf:byte,info3:bytepublic change3code segmentchange3 proc far assume cs:code sub ax,ax mov ch,4 mov cl,4 mov bx,4a8fhrotate: rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah