1、 汇编语言程序设计第一次上机作业1.从键盘上接受一个字符,找出他的前导字符和后继字符,按顺序显示这三个字符。寄存器分配:AL:存输入值 xDL:输出显示流程图:如右图所示DATA SEGMENTA DB 0DATA ENDSSTACK SEGMENT STACKDB 200 DUP(0)STACK ENDSCODE SEGMENTASSUME DS:DATA,SS:STACK,CS:CODES: MOV AX,DATAMOV DS,AXMOV AH,1INT 21HINC ALMOV DL,ALMOV AH,2INT 21HDEC ALMOV DL,ALMOV AH,2INT 21HDEC A
2、LMOV DL,ALMOV AH,2INT 21HCODE ENDSEND S开始输入AX(AL)+1ALALDL 显示(AL)-1ALALDL 显示(AL)-1 ALALDL 显示结束2.从键盘上输入一个数字字符,如不是,显示not odd,否则显示odd 。寄存器分配:AL:存输入值 xDL:输出显示流程图:如右图所示程序代码如下:DATA SEGMENTA DB 0BUF DB,NOT ODD$EA DB,ODD$DATA ENDSSTACK SEGMENT STACKDB 200 DUP(0)STACK ENDS YCODE SEGMENTASSUME DS:DATA,SS:STACK
3、,CS:CODES: MOV AX,DATA NMOV DS,AXMOV AH,1INT 21H YCMP AL,0JNGE BCMP AL,9JGE BLEA DX,EAMOV AH,9INT 21HJMP CB: LEA DX,BUFMOV AH,9INT 21HC: MOV AH,4CHINT 21HCODE ENDSEND S开始输入ALAL9显示 odd第二次上机作业1.将以 H 为首地址的字节存储区中的技能被 3 整除又能被 13 整除的无符号整数的个数(假定ajSTACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTBUF DB
4、 asfdcvbN=$-BUFB DW ?A DB 2DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,SS:STACKBEGIN:MOV AX,DATAMOV DS,AXLEA SI,BUFLEA DI,BUFMOV CX,NDEC CXMOV B,CXINC CXADD DI,BMOV AX,CXDIV ALOAP: MOV BL,DIMOV DL,SIXCHG BL,DLMOV SI,DLMOV DI,BLINC SIDEC DIDEC ALJNZ LOAPP2:LEA SI,BUFMOV DH,SIMOV DL,DHMOV AH,2INT 21HI
5、NC SILOOP P2NEXT: MOV AH,4CHINT 21HCODE ENDSEND BEGIN 第三次上机作业1.在以 BUF1 和 BUF2 为首地址的两个字存储区中,分别存放有 10 个不相等的无符号数。依次找出同时在这两个存储区中出现的数,将他们放在以 BUF3 为首地址的存储区中。寄存器分配:SI:BUF1 偏移地址 DI:BUF2 偏移地址 BP:BUF3 偏移地址 CX,DX:循环计数STACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTBUF1 DW 1,3,7,15,20,18,14,17,19,21BUF2 D
6、W 4,6,8,17,20,25,27,18,3,16BUF3 DW 10 DUP(?)DATA ENDSCODE SEGMENTASSUME CS:CODE,SS:STACK,DS:DATABEGIN: MOV AX,DATAMOV DS,AXLEA SI,BUFI YLEA DI,BUF2LEA BP,BUF3MOV CX,10 NMOV DX,10LOPA: MOV AX,SIMOV BX,DICMP AX,BX YJE BDEC DX NJZ CADD DI,2JMP LOPAB: MOV (BP),AXADD BP,2DEC DX JZJZ CADD DIJMP LOPA JNZC:
7、 LEA DI,BUF2INC SIMOV DX,10DEC CXJZ DJMP LOPA JNZD: MOV AH,4CHINT 21HBUF1 EASIBUF2 EADIBUF2 EABP10CX; 10BX开始(SI)AX(DI)BXAX=BXDX-1AX(BP)(BP)+2DX-1(DI)+2BUF2 EA DI(SI)+1; 10DXCX-1DX=0(DI)+2DATA ENDS END BEGIN JZ2.键盘接受一串字符到以 TAB 为首地址的字节存储区中,利用向前移动的方法,删除数字字符,然后在屏幕的下一行,显示删除后的字符串。寄存器分配:CX:计数控制循环 SI:TAB 首地
8、址 AL:存( SI) STACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTTAB DB 100 DUP(0)DATA ENDSCODE SEGMENTASSUME CS:CODE;SS:STACK;DS:DATABEGIN: LEA SI,TABMOV CX,10LOPA1: MOV AH,1INT 21H JNZMOV SI,ALMOV DL,AL JZMOV AH,2INT 21HDEC CXJNZ LOPA1MOV DL,0AHMOV AH,2 YINT 21HMOV SI,0 NMOV CX,10 YLOPA2: MOV AL,
9、SI NCMP AL,0JL ACMP AL,9JG AMOV BL,SILOPA3: INC SI JNZMOV SI,SI+1DEC CX JZJNZ LOPA3MOV SI,BLJMP LOPA2A: MOV DL,ALMOV AH,2 JNZINT 21HDEC CX JZJNZ LOPA2结束开始TAB EASI; 10CX输入SISIALALDL 显示CX-1换行;10CX;TAB EASISIALAL9 SIBLSI+1CX-1BLSIALDL 显示CX-1结束SI+1SI+1MOV AH,4CHINT 21HCODE ENDSEND BEGIN4.从键盘上接受若干个字符,以Z
10、结束,将其写到 C:ABC.ASM 文件中保存,然后显示在屏幕上。要求有提示信息。STACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTCE DBCREATE ERROR!,0AH,0DH ,$WE DBWRITE ERROR!,0AH,0DH,$PI DBPLEASE INPUT:,0AH,0DH,$F_NAME DBC:AB.ASM,0BUF DB 32767 DUP(?)F_NUM DW?DATA ENDSCODE SEGMENTASSUME SS:STACK;DS:DATA;CS:CODEBEGIN: MOV AX,DATAMOV
11、DS,AXMOV AH,3CHMOV CX,0LEA DX,F_NAME N YINT 21HJNC CLEA DX,CE NMOV AH,9INT 21H YJMP EXIT NC: MOV F_NUME,AXLEA DX,PIMOV AH,9INT 21HLEA DI,BUF YINPUT: MOV AH,1INT 21HMOV DI,ALINC DIMOV DL,DIMOV AH,2INT 21H开始创建文件成功 失败提示输入输入;BUF EADI;DI+1输入=Z输入为回车?换行;DI+1停止输入,写入文件夹显示关闭文件提示错误CMP AL,0DHJE ENDINCMP AL,0DHJ
12、NE INPUTMOV DL,0AHMOV DI,DLINC DIMOV AH,2INT 21HJMP INPUTENDINPUT: MOV AH,40HMOV BX,F_NUMLEA DX,BUFSUB DI,DXMOV CX,DIINT 21HJC ED: MOV AH,3EHINT 21HEXIT: MOV AH,4CHINT 21HE: LEA DX,WEMOV AH,9INT 21HJMP DCODE ENDSEND BEGIN 4. 从键盘上接受若干个字符,以Z 结束,将其写到 C:AB.ASM 文件中保存,然后显示在屏幕上。要求有提示信息。STACK SEGMENT STACKD
13、B 200 DUP(0)STACK ENDSDATA SEGMENTWDH DW ?WM DB C:AB.ASM,0BUFH DB 32676 DUP(?)BUF1 DB CREAT ERROR!,0AH,0DH, $BUF2 DB WRITE ERROR!,0AH,0DH,$BUF3 DB NO SPACE!,0AH,0DH,$结束BUF4 DB PLEASE INPUT:,0AH,0DH,$DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACKBEGIN:MOV AX,DATAMOV DS,AXMOV ES,AXMOV AH
14、,3CHMOV CX,0LEA DX,WMINT 21HJNC P1LEA DX,BUF1MOV AH,9INT 21HJMP NEXTP1:MOV WDH,AXLEA DX,BUF4MOV AH,9INT 21HLEA DI,BUFHP2:MOV AH,1INT 21HMOV BYTE PTR DI,ALCMP AL,1AHJE P3JMP P2P3:MOV AH,40HMOV BX,WDHLEA DX,BUFHSUB DI,DXMOV CX,DIINT 21HJC P4CMP AX,CXJE P5LEA DX,BUF3MOV AH,9INT 21HP5:MOV AH,3EHINT 21HM
15、OV DL,BXMOV AH,2INT 21HINC DXLOOP P5NEXT:MOV AH,4CHINT 21HP4:LEA DX,BUF2MOV AH,9INT 21HJMP P5CODE ENDSEND BEGIN5 从键盘上接受一存在的文本文件的名字,并将其内容分页显示出来。要求有信息提示。STACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTWDH DW ?WM DB 20DB ?DB 20 DUP (0)BUFH DB 32676 DUP(?)BUF1 DB PLEASE INPUT:,0AH,0DH,$BUF2 DB REA
16、D ERROR!,0AH,0DH,$BUF3 DB OPEN ERROR!,0AH,0DH,$DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACKBEGIN:MOV AX,DATAMOV DS,AXMOV ES,AXLEA DX,BUF1MOV AH,9INT 21HLEA DX,WMMOV AH,10INT 21HMOV AH,2MOV DL,0AHINT 21HMOV DL,0DHINT 21HMOV AL,WM+1MOV AH,0MOV BX,AXMOV BYTE PTR BX+WM+2,0LEA DX,WM+2MOV
17、AX,3D00HINT 21HJC P1MOV WDH,AXMOV BX,AXMOV CX,32767LEA DX,BUFHMOV AH,3FHINT 21HJC P2MOV AX,CXMOV BX,WDHMOV AH,3EHINT 21HMOV AH,2MOV DL,0AHINT 21HMOV DL,0DHINT 21HLEA BX,BUFHLOPA: MOV DL,BXMOV AH,2INT 21HINC BXLOOP LOPAEXIT: MOV AH,4CHINT 21HP1: LEA DX,BUF2MOV AH,9INT 21HJMPE EXITP2: LEA DX,BUF3MOV A
18、H,9INT 21HJMP EXITCODE ENDSEND BEGIN第四次上机作业1 在 STR 串中寻找SS:STACK;CS:CODE;STAR: MOV AX,DATAMOV DS,AXLEA DI,BUF DIBXLEA SI,BUFP: MOV AL,CS:CODE:SS:STACKSTA: MOV AX,DATAMOV DS,AXLEA DL,BUFMOV AH,9INT 21HLEA DX,AMOV AH,10INT 21HMOV DL,0DH NMOV AH,2INT 21HLEA SI,A YLEA DI,BA: MOV AL,SI NCMP AL,41HJL C YCM
19、P AL,5AHJEC BCMP AL,61HJL CCMP AL,71HJG CB:MOV DI,ALINC DI JNZC: INC SIDEC CX JZJNZ AMOV DI,$LEA AX,BMOV AH,10INT 21HMOV AH,4CH开始显示输入输入A回车换行ASIBDISIALAL0?Y结束N主 模 块 : EXTRN INTR45:FARPUBLIC BSTACK SEGMENT STACKDB 100 DUP(?)STACK ENDSDATA SEGMENTBUF DB 15,18,22,24,5n=$-BUFB DB ?DATA ENDSCODE SEGMENTAS
20、SUME CS:CODE,DS:DATA,SS:STACKSTART: MOV AX,SEG INTR45MOV DS,AXMOV DX,OFFSET INTR45MOV AX,2545HINT 21HMOV AX,DATAMOV DS,AXMOV BX,0LEA SI,BUFMOV BX,n-1MOV CX,nL1: MOV DH,SI+BXINT 45HMOV AH,2MOV DL, INT 21HDEC BXLOOP L1EXIT: MOV AH,4CHINT 21HCODE ENDSEND STARTINTR45 (DH)赋与AL10赋与B除以B求余对AL,AH换码依次输出AL,AH返
21、回子 模 块 :PUBLIC INTR45EXTRN B:BYTESTACK SEGMENT STACKDB 100 DUP(?)STACK ENDSCODE SEGMENTASSUME CS:CODE,SS:STACKINTR45 PROC FARMOV AL,DHMOV AH,0MOV B,10DIV BADD AL,30HADD AH,30HMOV B,AHMOV AH,2MOV DL,ALINT 21HMOV AH,2MOV DL,BINT 21HIRETENDPEXIT: MOV AH,4CHINT 21HCODE ENDSEND 输 出 : 05 24 22 18 152.设计一个
22、输入滚动区,接受一串字符写到文件 C:ABC.TXT 中。STACK SEGMENT STACKDB 200 DUP(0)STACK ENDSDATA SEGMENTF_NAME DBC:ABC.TXT,0F_NUM DW?BUFIN 32767 DUP(0) 失败DATA ENDSCODE SEGMENT 成功ASSUME DS:DATA;CS:CODE:SS:STACKBEGIN: MOV AX,DATAMOV DS,AXMOV AX,3CHMOV CX,0LEA DX,F_NAME INT 21HJNC ALEA DI,BUFINLEA DX,CEMOV AH,9INT 21HJMP E
23、XITA:MOV AH,6MOV AL,1MOV CX,0MOV DX,0901HINT 10MOV DX,0901HMOV AH,2INT 10INPUT: MOV CX,10 NMOV AH,0AHMOV AH,1 YINT 21HMOV DI,ALINC DIDEC CXJZ ENDINJMP INPUTENDIN: MOV AH,40HMOV BX,F_NUMLEA DX,BUFINSUB DI,DX开始BUFIN DI建立文件AXF_NUM设滚屏 9 行 9 列设光标在 9 行 1 列处提示输入10CX输入字符BUFINCX-1字符写入文件中关闭文件结束CX=0显示失败MOV CX,DIINT 21HB: MOV AH,3EHINT 21HEXIT : MOV AH,4CHINT 21HCODE ENDSEND BEGIN姓名:王飓烜学号:080107031130班级:08 软件工程 3 班汇编语言程序设计姓名:xxx学号:080107031xxx班级:08 软件工程 3 班