汇编上机实验报告心得体会.docx
汇编上机实验报告心得体会汇编语言程序设计 第一次上机作业 1.从键盘上接受一个字符,找出他的前导字符和后继字符,按顺序显示这三个字符。 寄存器分配: AL:存输入值x DL:输出显示 流程图:如右图所示 DATA SEGMENT A DB 0 DATA ENDS STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS CODE SEGMENT ASSUME DS:DATA,SS:STACK,CS:CODE S: MOV AX,DATA MOV DS,AX MOV AH,1 INT 21H INC AL MOV DL,AL MOV AH,2 INT 21H DEC AL MOV DL,AL MOV AH,2 INT 21H DEC AL MOV DL,AL MOV AH,2 INT 21H CODE ENDS END S 开始 输入 AX (AL)+1AL ALDL显示 -1AL ALDL显示 -1AL ALDL显示 结束 2.从键盘上输入一个数字字符,如不是,显示not odd,否则显示odd。 寄存器分配: AL:存输入值x DL:输出显示 流程图:如右图所示 程序代码如下: DATA SEGMENT A DB 0 BUF DB,'NOT ODD$' EA DB,'ODD$' DATA ENDS STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS CODE SEGMENT ASSUME DS:DATA,SS:STACK,CS:CODE S: MOV AX,DATA MOV DS,AX MOV AH,1 INT 21H CMP AL,'0' JNGE B CMP AL,'9' JGE B LEA DX,EA MOV AH,9 INT 21H JMP C B: LEA DX,BUF MOV AH,9 INT 21H C: MOV AH,4CH INT 21H CODE ENDS END S 开始 输入AL Y AL<0 N AL>9 显示 not odd Y 显示 odd 结束 第二次上机作业 1.将以H为首地址的字节存储区中的技能被3整除又能被13整除的无符号整数的个数显示出来;同时对应的显示它们分别对应的地址偏移量。 DATA SEGMENT 寄存器分配:SI:存H的偏移地址 H DW 1,3,5,39,13,117,15,17,$ CX:计数 N =$-H DX:存余数 B DW 3 BX:循环计数 开始 C DW 13 D DW 0 DATA ENDS STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS CODE SEGMENT ASSUME CS:CODE,SS:STACK,DS:DATA BEGIN: MOV AX,DATA MOV DS,AX MOV CX,0 MOV BX,N LEA SI,H LOPA: MOV AX,SI DIV B MOV D,DX JNZ NEXT DIV C MOV D,DX JNZ NEXT MOV DL,SI MOV AH,2 INT 21H INC CX INC SI DEC DX JNZ LOPA NEXT: INC SI DEC DX JNZ LOPA EXIT: MOV DL,CL MOV AH,2 INT 21H MOV AH,4CH INT 21H H偏移SI NBX 0CX AX N (AX)mod3=0Y N (AX)mod13=0 Y SIDL显示 +1 CX+1 N DX-1=0 Y CX显示 结束 CODE ENDS END BEGIN 2.在以TAB为首地址的字存储区中存放有n个无符号数,统计低三位全为一的数的个数。 寄存器分配:SI:TAB的偏移地址 AX:存SI DX:计个数 CX:循环计数 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT TAB DW '1,9,10,20,30,40 ' N =($-TAB)/2 DATA ENDS CODE SEGMENT ASSUME CS:CODE,SS:STACK,DS:DATA BEGIN: MOV AX,DATA MOV DS,AX MOV DX,0 MOV CX,N MOV BX,7H LEA SI,TAB LOPA: MOV AX,SI AND AX,BX CMP AX,BX JNE EXIT INC DX INC SI DEC CX JNZ LOPA NEXT: INC SI DEC CX JNZ LOPA EXIT: MOV DL,DL MOV AH,2 INT 21H MOV AH,4CH INT 21H CODE ENDS EMD BEGIN 开始 TAB首地址SI 7HBX;0DL NCX (SI)AX (AX)AND(BX)AX N AX=BX Y +1 DL+1DL (SI)+1SI (CX)-1CX CX=0 N 显示 DL 结束 3键盘接受一串字符到BUF为首地址的字节单元中,要求用下列方法分别编程,将它们以相反的次序显示在屏幕的下一行中: (1).按地址从尾向前依次显示。 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT BUF DB 20 DB ? DB 20 DUP(0) BUF1 DB 20 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX LEA DX,BUF MOV AH,10 INT 21H MOV CL,BUF+1 MOV CH,0 LEA DI,BUF1 P1: LEA SI,BUF+2 ADD SI,CX DEC SI MOV AL,SI MOV BYTE PTR DI,AL INC DI MOV DL,AL MOV AH,2 INT 21H LOOP P1 NEXT: MOV AH,4CH INT 21H CODE ENDS END BEGIN (2).利用堆栈反向显示。 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT BUF DB 20 DB ? DB 20 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX LEA DX,BUF MOV AH,10 INT 21H MOV CL,BUF+1 MOV CH,0 LEA SI,BUF+2 P1: MOV AL,SI MOV AH,0 PUSH AX INC SI LOOP P1 P2: POP BX MOV DL,BL MOV AH,2 INT 21H MOV CL,BUF+1 MOV CH,0 LOOP P2 NEXT: MOV AH,4CH INT 21H CODE ENDS END BEGIN (3).利用交换的方法反序后, 然后显示:即ai<>aj STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT BUF DB 'asfdcvb' N=$-BUF B DW ? A DB 2 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX LEA SI,BUF LEA DI,BUF MOV CX,N DEC CX MOV B,CX INC CX ADD DI,B MOV AX,CX DIV A LOAP: MOV BL,DI MOV DL,SI XCHG BL,DL MOV SI,DL MOV DI,BL INC SI DEC DI DEC AL JNZ LOAP P2:LEA SI,BUF MOV DH,SI MOV DL,DH MOV AH,2 INT 21H INC SI LOOP P2 NEXT: MOV AH,4CH INT 21H CODE ENDS END BEGIN 第三次上机作业 1.在以BUF1和BUF2为首地址的两个字存储区中,分别存放有10个不相等的无符号数。依次找出同时在这两个存储区中出现的数,将他们放在以BUF3为首地址的存储区中。 寄存器分配:SI:BUF1偏移地址 DI:BUF2偏移地址 BP:BUF3偏移地址 CX,DX:循环计数 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT BUF1 DW 1,3,7,15,20,18,14,17,19,21 BUF2 DW 4,6,8,17,20,25,27,18,3,16 BUF3 DW 10 DUP(?) DATA ENDS CODE SEGMENT ASSUME CS:CODE,SS:STACK,DS:DATA BEGIN: MOV AX,DATA MOV DS,AX LEA SI,BUFI LEA DI,BUF2 LEA BP,BUF3 MOV CX,10 MOV DX,10 LOPA: MOV AX,SI MOV BX,DI CMP AX,BX JE B DEC DX JZ C ADD DI,2 JMP LOPA B: MOV (BP),AX ADD BP,2 DEC DX JZ C ADD DI JMP LOPA C: LEA DI,BUF2 INC SI MOV DX,10 DEC CX JZ D JMP LOPA D: MOV AH,4CH INT 21H DATA ENDS END BEGIN 开始 BUF1 EASI BUF2 EADI BUF2 EABP 10CX; 10BX (SI)AX (DI)BX Y AX=BX N DX-1 DX=0 Y N (DI)+2 AX (BP)+2 JZ DX-1 JNZ (DI)+2 BUF2 EA DI (SI)+1; 10DX JNZ CX-1 JZ 结束 2.键盘接受一串字符到以TAB为首地址的字节存储区中,利用向前移动的方法,删除数字字符,然后在屏幕的下一行,显示删除后的字符串。 寄存器分配:CX:计数控制循环 SI:TAB首地址 AL:存 开始 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT TAB DB 100 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS:CODE;SS:STACK;DS:DATA BEGIN: LEA SI,TAB MOV CX,10 LOPA1: MOV AH,1 INT 21H MOV SI,AL MOV DL,AL MOV AH,2 INT 21H DEC CX JNZ LOPA1 MOV DL,0AH MOV AH,2 INT 21H MOV SI,0 MOV CX,10 LOPA2: MOV AL,SI CMP AL,0 JL A CMP AL,9 JG A MOV BL,SI LOPA3: INC SI MOV SI,SI+1 DEC CX JNZ LOPA3 MOV SI,BL JMP LOPA2 A: MOV DL,AL MOV AH,2 INT 21H DEC CX JNZ LOPA2 MOV AH,4CH TAB EASI; 10CX 输入SI SIAL SI+1 ALDL显示 CX-1 JNZ JZ 换行;10CX;TAB EASI SIAL AL<0 Y N AL>9 Y N SIBL SI+1 SI+1 JNZ CX-1 JZ BLSI ALDL显示 JNZ CX-1 JZ 结束 INT 21H CODE ENDS END BEGIN 4.从键盘上接受若干个字符,以Z结束,将其写到C:ABC.ASM文件中保存,然后显示在屏幕上。要求有提示信息。 开始 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT CE DBCREATE ERROR!,0AH,0DH ,$ WE DBWRITE ERROR!,0AH,0DH,$ PI DBPLEASE INPUT:,0AH,0DH,$ F_NAME DBC:AB.ASM,0 BUF DB 32767 DUP(?) F_NUM DW? DATA ENDS CODE SEGMENT ASSUME SS:STACK;DS:DATA;CS:CODE BEGIN: MOV AX,DATA MOV DS,AX MOV AH,3CH MOV CX,0 LEA DX,F_NAME 输入;BUF EADI;DI+1 提示输入 成功 创建文件 失败 N 输入=Z Y INT 21H JNC C LEA DX,CE MOV AH,9 INT 21H JMP EXIT C: MOV F_NUME,AX LEA DX,PI MOV AH,9 INT 21H LEA DI,BUF INPUT: MOV AH,1 INT 21H MOV DI,AL INC DI MOV DL,DI MOV AH,2 INT 21H CMP AL,0DH N 输入为回车? Y N 换行;DI+1 提示错误 停止输入,写入文件夹 Y 显示 关闭文件 结束 JE ENDIN CMP AL,0DH JNE INPUT MOV DL,0AH MOV DI,DL INC DI MOV AH,2 INT 21H JMP INPUT ENDINPUT: MOV AH,40H MOV BX,F_NUM LEA DX,BUF SUB DI,DX MOV CX,DI INT 21H JC E D: MOV AH,3EH INT 21H EXIT: MOV AH,4CH INT 21H E: LEA DX,WE MOV AH,9 INT 21H JMP D CODE ENDS END BEGIN 4. 从键盘上接受若干个字符,以Z结束,将其写到C:AB.ASM文件中保存,然后显示在屏幕上。要求有提示信息。 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT WDH DW ? WM DB 'C:AB.ASM',0 BUFH 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 ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX MOV ES,AX MOV AH,3CH MOV CX,0 LEA DX,WM INT 21H JNC P1 LEA DX,BUF1 MOV AH,9 INT 21H JMP NEXT P1:MOV WDH,AX LEA DX,BUF4 MOV AH,9 INT 21H LEA DI,BUFH P2:MOV AH,1 INT 21H MOV BYTE PTR DI,AL CMP AL,1AH JE P3 JMP P2 P3:MOV AH,40H MOV BX,WDH LEA DX,BUFH SUB DI,DX MOV CX,DI INT 21H JC P4 CMP AX,CX JE P5 LEA DX,BUF3 MOV AH,9 INT 21H P5:MOV AH,3EH INT 21H MOV DL,BX MOV AH,2 INT 21H INC DX LOOP P5 NEXT:MOV AH,4CH INT 21H P4:LEA DX,BUF2 MOV AH,9 INT 21H JMP P5 CODE ENDS END BEGIN 5从键盘上接受一存在的文本文件的名字,并将其内容分页显示出来。要求有信息提示。 STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT WDH DW ? WM DB 20 DB ? DB 20 DUP (0) BUFH DB 32676 DUP(?) BUF1 DB 'PLEASE INPUT:',0AH,0DH,'$' BUF2 DB 'READ ERROR!',0AH,0DH,'$' BUF3 DB 'OPEN ERROR!',0AH,0DH,'$' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX MOV ES,AX LEA DX,BUF1 MOV AH,9 INT 21H LEA DX,WM MOV AH,10 INT 21H MOV AH,2 MOV DL,0AH INT 21H MOV DL,0DH INT 21H MOV AL,WM+1 MOV AH,0 MOV BX,AX MOV BYTE PTR BX+WM+2,0 LEA DX,WM+2 MOV AX,3D00H INT 21H JC P1 MOV WDH,AX MOV BX,AX MOV CX,32767 LEA DX,BUFH MOV AH,3FH INT 21H JC P2 MOV AX,CX MOV BX,WDH MOV AH,3EH INT 21H MOV AH,2 MOV DL,0AH INT 21H MOV DL,0DH INT 21H LEA BX,BUFH LOPA: MOV DL,BX MOV AH,2 INT 21H INC BX LOOP LOPA EXIT: MOV AH,4CH INT 21H P1: LEA DX,BUF2 MOV AH,9 INT 21H JMPE EXIT P2: LEA DX,BUF3 MOV AH,9 INT 21H JMP EXIT CODE ENDS END BEGIN 第四次上机作业 1在STR串中寻找&,若找到删除,并分两行显示删除前后的字符串;若找不到,则显示“find fall”. STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT BUF DB 3,2,5,4,&M,9,&,A,A COUNT EQU $-STR DATA ENDS CODE SEGMENT ASSUME DS:DATA;SS:STACK;CS:CODE; STAR: MOV AX,DATA MOV DS,AX LEA DI,BUF LEA SI,BUF P: MOV AL,& REPNE SCASB JNE EXIT MOV SI,DI A: MOV BX,DI+1 MOV DI,BX INC DI CMP DI,COUNT JNE A SUB COUNT MOV CX,COUNT JZ EXIT MOV DI,SI SUB CX,SI JNZ P MOV CX,COUNT LEA SI,BUF B: LOBSB MOV DL,AL MOV AH,2 INT 21H DEC CX JNZ B EXIT: MOV AH,4CH INT 21H CODE ENDS END STAR 开始 BUFDI COUNT cx 查找$ DIBX DI+1 N DI=COUNT Y COUNT-1CX=0 SIDI JNZ CX-SIcx=0 Y COUNTcx StrSI 显示 结束 (2).将显示字符串和回车换行的指令段分别编一宏定义,然后调用; WRITE MACRO A LEA DX,A MOV AH,9 INT 21H ENDM CRLF MACRO A MOV AH,2 MOV DL,0AH INT 21H MOV DL,0DH INT 21H ENDM STACK SEGMENT STACK DB 200 DUP (0) STACK ENDS DATA SEGMENT STR DB 'ABC&D $' N =$-STR BUF DB 'FIND ERROR! $' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,STR LEA DI,STR MOV CX,N WRITE STR CRLF CLD P1: LODSB CMP AL,'&' JE P2 STOSB P2: LOOP P1 CMP SI,DI JNE P3 WRITE BUF JMP NEST P3: WRITE STR NEST: MOV AX,4C00H INT 21H CODE ENDS END BEGIN (3).将显示字符串和回车换行的指令段编成宏定义,存入宏库中,然后调用。 INCLUDE C:Users小鹰Desktop123.txt STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT STR DB 'ABC&D $' N =$-STR BUF DB 'FIND ERROR! $' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK BEGIN:MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,STR LEA DI,STR MOV CX,N WRITE STR CRLF CLD P1: LODSB CMP AL,'&' JE P2 STOSB P2: LOOP P1 CMP SI,DI JNE P3 WRITE BUF JMP NEST P3: WRITE STR NEST: MOV AX,4C00H INT 21H CODE ENDS END BEGIN 2.利用串指令编程,从键盘上接受一串字符,排除其中非字母字符后在令一排上显示. STACK SEGMENT STACK DB 200 DUP (0) STACK ENDS DATA SEGMENT A DB 10 DUP(?) B DB 10 DUP(?) BUF DB PLEASE INPUT:$ DATA ENDS CODE SEGMENT ASSUME DS:DATA;CS:CODE:SS:STACK STA: MOV AX,DATA MOV DS,AX LEA DL,BUF MOV AH,9 INT 21H LEA DX,A MOV AH,10 INT 21H MOV DL,0DH MOV AH,2 INT 21H LEA SI,A LEA DI,B A: MOV AL,SI CMP AL,41H JL C CMP AL,5AH JEC B CMP AL,61H JL C CMP AL,71H JG C B:MOV DI,AL INC DI C: INC SI DEC CX JNZ A MOV DI,$ LEA AX,B MOV AH,10 INT 21H MOV AH,4CH INT 21H 开始 显示输入 输入A 回车换行 ASI BDI SIAL AL<41H Y N AL<61H Y ALdi ;DI+1 N SI+1 JNZ CX-1 JZ $DI BDX显示 结束 CODE ENDS END STA 3.利用串编程:在一字符串中搜索一字符$,如果找到,显示其在串中的位置,否则,显示no