《计算机与信息学院实验报告 (15).docx》由会员分享,可在线阅读,更多相关《计算机与信息学院实验报告 (15).docx(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、合肥工业大学计算机与信息学院实验报告课 程:汇编语言程序设计专业班级:计算机13-3学 号:2013211704 姓 名: 姜敬超RESULTY DB OAH,OBH:YES,,$RESULTN DB 0AH,0BH;NO7$fDATA ENDSDSEG SEGMENTSTRING DB asmDSEG ENDSCODE SEGMENTASSUME CS:CODE,DS:DATA,ES:DSEGSTART:MOV AX,DATAMOV DS,AXMOV AX,DSEGMOV ES,AXLEA DI,STRINGMOV BX,DI;保存DI的初始值以恢复LEA DX,TIPMOV AH,9INT
2、21HLEADX,BUF ;从键盘中读入一个字符串MOV AH,0AHINT21HLEA SLBUFMOVAL,SI+1;输入字符串的长度放在AHADD SI,2MOV DX,SI;保存si的初始值CLDAGAIN:MOV CX,3REPZ CMPSBCMP CX,0JZ FOUNDMOV DI,BXINC DXMOV SI,DXDEC ALJNZ AGAINLEADX,RESULTN ;没有找至U,输出NOJMP DONEFOUND:LEA DX,RESULTY ;找到输出 YESDONE:MOV AH,9INT21HMOV AH,4cHINT21HCODE ENDSEND START四.结
3、果(包括必要的截图)1.DOSBox 0.74, Cpu speed: 3000 cycles, Frameskip 0, Program: DEBUG X以im File EX1.EXE1:List File NUL.MAP:Libraries .LIB:LINK : earning L40Z1: no stack segmentkC:SOFTOAREMASMEX1.EXE:SOFTWAREMASMC:SOFTOAREMASMDEBUGtU|073F:0100 0?3F:0102 IO73F:01O5 073F:0108 |O73F:0109 O73F:O10D |073F:0111 073
4、F:O11Z O73F:0113 073F:0115 O73F:0119 O73F:011B O73F:011F-tU|073F:0100 0?3F:0102 IO73F:01O5 073F:0108 |O73F:0109 O73F:O10D |073F:0111 073F:O11Z O73F:0113 073F:0115 O73F:0119 O73F:011B O73F:011F-tU|073F:0100 0?3F:0102 IO73F:01O5 073F:0108 |O73F:0109 O73F:O10D |073F:0111 073F:O11Z O73F:0113 073F:0115 O
5、73F:0119 O73F:011B O73F:011F-7403 E93700B805O0 50 FF363CZ1 FFAEFE0OF0 46 7400 00BZO0BZ 1499 0OZE07ZE07H H K:FUSSfpcc:DCDPzmduumonzdddojjmppjlijaaap0105019CAX,0005AX Z13C FAR BP+0OFESI0115 BP*SI+BZ0O,DHAL, 99 ZE07,CHES2.Z:SET BLASTER=AZZ0 17 DI H5 T6Z:mount c d:/Drive C is mounted as local directory
6、d:/Z:c:C:cd softwareC:SOFTWAREcd masmC: S0FTUAREf1ASMexZ. exeThe result is4B 5A 44C : SOF1WREMASM3.C :cd softwareC:SOFTWAREcd masmb:SOFIWAREMASMexZ.exe The result is4B 5A 44 C:SOFIUAREMASMex 11 legal command: ex.C:S0FIMAREMASMex3.exe INPUT CHARS LESS THAN Z55: asmdefYES|C:、SOF1WREMASM_五.实验体会在实验中编写了完
7、整的汇编语言程序段进一步了解了汇编语言,但是感觉编写 汇编语言是逻辑总是混乱的,有时结果莫名其妙,不过也借此明白了许多汇编 中需要注意的问题,比如算数运算中要注意数据位扩展等。实验三汇编语言子程序设计(分支、子程序)一.实验目的1、掌握分支和子程序结构和设计方法;2、熟悉在PC机上建立、汇编、连接、调试和运行8086/8088汇编语言程序的过程。3、通过汇编语言了解高级语言的参数传递等知识。二.实验内容1、1.BL中的只有一位为1。编写程序测试,并输出提示信息“The X Bit is 1”, 要求:地址表和转移表。2 .编写一个子程序计算z=f(x,y)=x*y+x-y (x,y,z有符号数
8、内存数)。要求通过堆 栈(寄存器、内存)传送所有参数。3 .实践CAsm的转换过程。三.实验过程和程序(l)address:DATA SEGMENTNONE DB 旧VERY BIT IS 0;0AH,0DH;$fADDRTB DWL0,Ll,L2,L3,L4,L5,L6,L7SO DB THE 0 BIT IS l0AH,0DH;$!SI DB THE 1 BIT IS l;0AH,0DH却S2 DB THE 2 BIT IS,0AH,0DH,$S3 DB THE 3 BIT IS l,0AH,0DH,$S4 DB THE 4 BIT ISr,0AH,0DH,$S5 DB THE 5 BIT
9、 IS,0AH,0DH,$S6 DB THE 6 BIT IS l,0AH,0DH;$S7 DB THE 7 BIT IS,0AH,0DH,$DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMOV CH,8MOV SI,-2MOV BL,2AGAIN:DEC CH ;记录位移的总次数CMP CH,-1JZ NONE! ;BL全为0处理ADD SI,2 ;计算n号分支地址SHR BL,1JNC AGAINJMPADDRTBSILO:LEA DX,S0JMP DONELEA DX,S1JMP DONEL2:L
10、EA DX,S2JMP DONEL3:LEA DX,S3JMP DONEL4:LEA DX,S4JMPDONEL5:LEA DX,S5JMP DONEL6:LEA DX,S6JMP DONEL7:LEA DX,S7JMP DONENONEI:LEA DX,NONEDONE:MOV AH,9 ;输出结果INT21HMOV AH,4CHINT21HCODE ENDSEND START(2).JMPDATA SEGMENTSO DB THE 0 BIT IS l,0AH,0DH,$S I DB THE 1 BIT IS,0AH,0DH,$S2 DB THE 2 BIT IS l0AH,0DH;$!S
11、3 DB THE 3 BIT IS1,0AH,0DH,$S4 DB THE 4 BIT IS l,0AH,0DH,$S5 DB THE 5 BIT IS l0AH,0DH;$fS6 DB THE 6 BIT IS l,0AH,0DH,$S7 DB THE 7 BIT IS l0AH,0DH;$!NONE DB EVERY BIT IS 0;0AH,0DH;$,DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMOV CH,8MOV AX,-3MOV BL,4AGAIN:DEC CH ;记录位移总次数CMP
12、CH,-1 ;bl 是否全 0JZ NONEI ;BL 全。处理ADD AX,3 ;计算n号分支地址SHR BLJNC AGAINLEA SIJMPTBADD SI,AXJMPSIJMPTB:JMP NEAR PTR LOJMP NEAR PTR LIJMP NEAR PTR L2JMP NEAR PTR L3JMP NEAR PTR L4JMP NEAR PTR L5JMP NEAR PTR L6JMP NEAR PTR L7LO:LEA DX,S0JMPDONELI:LEA DX,S1JMP DONEL2:LEA DX,S2JMP DONEL3:LEA DX,S3JMP DONEL4:LE
13、A DX,S4JMP DONEL5:LEA DX,S5JMP DONEL6:LEA DX,S6JMP DONEL7:LEA DX,S7JMP DONENONEI:LEA DX,NONEDONE:MOV AH,9 ;输出结果INT21HMOV AH,4CHINT21HCODE ENDSEND START2.DATA SEGMENTORGOXDW 1234HY DW 5678HZDDODATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXSUB SP,4 ;为返回参数双字z留空间PUSH X ;堆栈传递参数xPUS
14、H Y ;堆栈传递参数yCALLFXYZLEA BX,ZPOP WORD PTRBXPOP WORD PTRBX+2MOV AH,4CHINT21HFXYZ PROC NEAR ;子程序PUSH BPMOV BP,SP ;当前栈顶指针传给bp, bp作为读写指针PUSH AX ;保护现场PUSH BXPUSH DXMOV AX,6BPMOV BX,4BP IMUL BXADD AX,6BPADC DX,0SUB AX,4BPSBB DX,0MOV 8BP,AXMOV 10BP,DXPOP DXPOPBXPOP AXPOP BPRET 4FXYZENDPCODE ENDSEND START四.实
15、验结果(包括必要的截图)蠲 DOSBox 0.74, Cpu speed: 3000 cycles. Frameskip 0, Program: DOSBOXXZ:SET BLASTER=AZZO I? DI H5 T6Z:mount c d:zDrive C is mounted as local directory d:/Z:c:C:cd softwareC:SOFTWAREcd masmC:SOFTWAREMASMexZ.exeThe result is4B 5A 44C:SOFTOAREXMASMex11 legal command: ex.C:S0FTWAREMASMex3.exeI
16、NPUT CHARS LESS THAN Z55:asmdefYESC:S0FTWAREMASMex31.exeTHE 1 BIT IS 1C:SOFTWAREMASMaDOSBox 0.74, Cpu speed: 3000 cycles, Frameskip 0, Program: DOSBOXc d:/Drive C is mounted as local directory d:/Z:c:C:cd softwareC:SOFTUAREcd masmC:SOFTWAREMASMexZ.exeThe result is4B 5A 44C:SOFTWAREMASMex11 legal com
17、mand: ex.C:S0FTWAREXMASMex3.exeINPUT CHARS LESS IBAN Z55:asmdefYESC:S0FTWAREMASMex31.exeTHE 1 BIT IS 1C:S0FTWAREMASMex3Z.exeTWE Z BIT IS 1C:SOFTWAREMASMaDOSBox 0.74, Cpu speed: 3000 cycles, Frameskip 0, Program: DEBUG XC:S0FTWAREMASMex3Z.exeTHE Z BIT IS 1C:S0FTWAREMASM3EXZ.exeC : S0FTWREMASMdebug-u实
18、验一 Debug程序的使用O?3F:0100 0000ADDBX+SI,AL073F:010Z 0000ADDBX*SU,AL073F:0104 0000ADDBX*SD,ALG73F:0106 0000ADDBX+SI,ALO73F:0108 0000ADDBX+SH,ALO73F:010A 0000ADDBX+SU,AL073F:01OC 0000ADDBX*SI,ALO73F:010E 0000ADDBX*SI,AL?3F:0110 0000ADDBX*SH,ALG73F:011Z 0000ADDBX*SI,AL073F:0114 0000ADDBX+SI,AL073F:0116 000
19、0ADDBX*SU,AL073F:0118 0000ADDBX*SH,ALO73F:011A 0000ADDBX+SI,ALG73F:011C 3400XORAL,00O73F:011E ZECS:G?3F:011F 07POPES一.实验目的1、熟悉DEBUG程序中的命令,学会在DEBUG下调试运行汇编语言源程序。2、掌握8086/8088的寻址方式及多字节数据的处理方法。二.实验内容1、利用DEBUG程序中的“E”命令,将两个多字节数“ 12345678H”和 “FEDCBA98H”分别送入起始地址为DS:0200H和DS:0204H两个单元中。2、分别用直接寻址方式和寄存器间接寻址方式编
20、写程序段,实现将DS:0200H 单元和DS:0204H单元中的数据相加,并将运算结果存放在DS9208H单元中。要求:本次实验的内容均在DEBUG下完成,实现数据的装入、修改、显示;汇编 语言程序段的编辑、汇编和反汇编;程序的运行和结果检查。附加题:1. 从DS:0000H开始的5个16位带符号数分别记为x,y,z,v,w,用E命令初始化为:540,1,-1,1080,0,试求 w=(v-(x*y+z-540)/x完成BX中1的个数的统计。三.实验过程和程序L实验指导书中2.代码已在图中附加2:将二进制数利用右移指令依次移进cf判断cf是否为1如此循环mov bx,1233xor ax,ax
21、 ;清空mov ex,16again: shr bx,ladc ax,0loop again3.配置(C):活动(Debug)常规 联 VC+目录/ C/C+ + 常规 跳 预处理器 代码生成 语言译头 端出文件 浏览信息 高级 所有选项I opfr扩展特性化源汇编程序蜿出平台(P):活动(Win32)为:匚编叫列UnicodeASM歹!J表位置对象文件名程序S有库文件名生成XML文档文件XML 的汇编程序输出指定汇编语言域出文件的内容。无列表无列表仅有程序集的列表(/FA)帝机器码的程序集(/FAc)帝源代码的程序集(/FAs)程序集、机器码和源代码(/FAcs)$(lntDir)(/FA.
22、 /FAc, /FAs, /FAcs)配置管理器(0)确定取;肖应用(A五.实验体会实验一中尝试着做了地址表跟转移表但是不太理解,虽然程序实现可以看懂, 但仅限于模仿。在实验二中寄存器跟内存传址比较容易实现,但是堆栈传址中总是出错,智 商有限所以只能求助大神,最后勉强完成。实验三只是根据老师上课所讲进行了尝试,不过看不明白转换后的汇编文件。实验四汇编语言高级编程专题一.实验目的1、汇编语言宏程序设计;2、掌握中断服务子程序的编写。3、汇编语言与高级语言的混编。二.实验内容1、编写一个宏,求三个数的最小数,原型为:MIN3 x,y,z,min2、挂接1CH中断,正计时60秒后退出。要求屏幕显示0
23、-59的秒数。3、VC+中编写内联汇编,将字节数组的每个元素高低四位互换。char dbyte = 0x34,0x45,0x56,0x67,Oxaf;三.实验过程和程序 1.MIN3 MACRO X,Y,Z,MINPUSH AX PUSH BX PUSH CXMOV AX,X ;只能用寄存器比较 MOV BX,Y MOV CX,Z CMPAX,BX JG NEXT CMP AX,Z JG NEXT1MOV MIN,AX JMP DONENEXT:CMP BX,Z JG NEXT1 MOV MIN,BX JMP DONENEXT1:MOV MIN,CXDONE:POP exPOPBX POP A
24、XENDMDATA SEGMENTX DW 1234HYDW 1111001110010110BZ DW 9999 MIN DW ?DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMIN3 X,Y,Z,MINMOV AH,4CHINT21HCODE ENDS END STARTINTNO EQU 1CHUSEINT = 1DATA SEGMENT OLDISR DW ?,?TIMER DB 100COUNTER DW 0ISDONE DB 0DATA ENDSCODE SEGMENTASSUME CS:C
25、ODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMOV AX,0MOV ES,AXIF USEINTMOV AL, INTNOMOV AH,35HINT21HMOV OLDISR0, BXMOV AX,ESMOV OLDISR2,AXELSECLIMOV AX, ES:INTNO*4MOV OLDISR0,AXMOV AX,ES:INTNO*4+2MOV OLDISR2, AXSTIENDIFIF USEINTPUSH DSMOV AX, SEG ISRMOV DS,AXMOV DX, OFFSET ISRMOV AL, INTNOMOV AH, 25HINT21HP
26、OP DSELSECLIMOV WORD PTR ES:INTNO*4, OFFSET ISRMOV WORD PTR ES:INTNO*4+2,SEG ISRSTIENDIFWAITHERE:CMP ISDONEJJNZ WAITHEREEXIT:IF USEINTPUSH DSMOV DX,OLDISR0MOV AX,OLDISR2MOV DS,AXMOV AL, INTNOMOV AH, 25HINT21HPOP DSELSECLIMOV AX,OLDISR0MOV ES:INTNO*4,AXMOV AX,OLDISR2MOV ES:INTNO*4+2,AXSTIENDIFMOV AX,
27、4C00HINT21HISR PROC FARPUSH DXPUSH AXMOV AX,DATAMOV DS,AXSTI;便于中断嵌套INC TIMERAGAIN:CMP TIMER, 1000/55 ;18JB DONEMOV TIMER,。MOV AH,2MOV DL3INT21HMOV AX,COUNTERMOV DL,10DIV DLMOV DH,AHMOV DL,ALMOV AH,2ADD DL,30HINT21HMOV DL,DHADD DL,30HINT21HINC COUNTERCMP COUNTERS。JB DONEMOV ISDONEDONE:PUSHFCALL DWORD
28、 PTR OLDISRCLIPOP AXPOP DXIRETISR ENDPCODE ENDSEND START#include nstdafx.hH#include#includeusing namespace std;int main()char dbyte5 = 0x34, 0x45, 0x56, 0x67, Oxaf ;cout ”交换之前: endl;for (int i = 0; i 5; i+) cout dbytei )cout endl;_asmmov cl,4mov ch,5xor bx,bxmov esi,0again:ror byte ptr dbyteesi9clin
29、c esidec chjnz againcout ”交换后:H endl;for (intj = 0;jcd masmC: S0FTWREMASM4exl. exeC:SOFTWAREMASMdebugnJ:073F : 0100 G73F:010Z O73F:0104 b?3F:0106 K)73F:0106 ?3F:01QA G73F:O10C 073F:010E 073F:010F O73F:0111 073F:011Z 0?3F:0113 073F:O115 0?3F:0119 073F:011D O73F:011E 073F:011F-nJ:073F : 0100 G73F:010Z
30、 O73F:0104 b?3F:0106 K)73F:0106 ?3F:01QA G73F:O10C 073F:010E 073F:010F O73F:0111 073F:011Z 0?3F:0113 073F:O115 0?3F:0119 073F:011D O73F:011E 073F:011F-nJ:073F : 0100 G73F:010Z O73F:0104 b?3F:0106 K)73F:0106 ?3F:01QA G73F:O10C 073F:010E 073F:010F O73F:0111 073F:011Z 0?3F:0113 073F:O115 0?3F:0119 073F
31、:011D O73F:011E 073F:011F-0000000000000000000000000000 AE FE00F0467400 00BZOOBZ 0G990OZE07 ZE07s KDDDDDDDACCC D D P : PDDDDDDDCNONZDDOSOAAAAAAASILIJAAPCPBX+SIJ,AL BX+SI,AL BX*SI,AL BXSILAL BX*SH,AL BX*SI,AL BX+SU,ALBYTE PTR BX*SHSI0115BP+SI+BZ00,DH BX+DI+ZE00,BL ESES2.DOSBox 0.74, Cpu speed: 3000 cy
32、cles, Frameskip 0, Program: 4EX2 XThe DOSBox Team http:z/乙:、)SET BLASTER=AZZO I? DI H5 T6c d;/Directory d;z doesnt exist.E:c:Driue C does not exist?You mustit first. Type intro or intro mount for more information.IZ:mount c d:Directory d: doesnt exist.c d:/Drive C is mounted as local directory d:/IC
33、 :cd softwareC :S0FlWREcd masmC:S0FTWAREXMASM4exZ.exe03DOSBox 0.74, Cpu speed: 3000 cycles, Frameskip 0, Program: DOSBOX XList File NUL.MAP1: Libraries .LIB:LINK : earning L40Z1: no stack segmentC:SOFTOAREMASMC:S0FTUAREMASM4exZ.exe 59C:SOFTWAREMASMa11 legal command: a.C:S0FTUAREMASM4exZ.exe59C:SOFTW
34、REMASMa11 legal command: a.C:SOFTWAREMASMC:SOFTOAREMASMC:SOF1WREMASMC:SOFTWAREXMASMC:SOFTWAREMASM3.ConsoleApphcationl - Microsoft Visual Studio(W)帮助(H)(W)帮助(H)(W)帮助(H)文件(D 编辑视图&) 项目 生成调试团队(M) 工具CD 测试体系结构 分析) O *50 * wl H bH *9 * Windows 器 Debug Win32 ConsoleApphcationl .cpp# 中 X ConsoleApplication1
35、O mainQusing namespace std; int main() char dbyte 5 = 0x34, 0x45, 0x56, 0x67, Oxaf ; cout ”交换之前: endl;for (int i = 0; i 5; i+) cout dbytei f;cout endl;_asmmov cl, 4mov ch, 5 xor bx,bx mov esi, 0 again:ror byte ptr dbyteesi, cl inc esi dec ch jnz again cout 交换后: endl: for (int j = 0; j 5; j+) cout 32
36、cMd. exe - debug13D4:0100 MOU13D4:010313D4:01073D4:010B3D4:010F13D4:011213D4:0116-u CS:0100MOU ADD ADC MOU MOUAX.0200 BX/02021 AX,0204 BX/0206 0208LAX 020ALBX3D4:01003D4:010313D4:010713D4:010B13D4:010F3D4:01123D4:011613D4:011813D4:011A13D4:011C3D4:011E3D4:011FA10002 8B1E0202 03060402 131E0602 A30802
37、 891E0A02 0000 0000 0000 3400 C3 1300MOU MOU ADD ADC MOU MOU ADD ADD ADD XOR RET ADCAX,0200 BX.0202 AX,0204 BX/0206 0208LAX 020ALBX BX+SI,AL BX-SI LAL BXSI LALAL.00AX,BX+SIA0000 BX=0000 CX=0000 DX=0000 SP=FFEES=13D4 ES=13D4 SS=13D4 CS=13D4 IP=01003D4:0100 A10002MOUAX.0200BP=0000 SI=0000 DI=0000NU UP
38、 EI PL NZ NA PO NCDS:0200=5678-e-aX=1110 BX=0208 CX=0000 DX=1111 SP=FFEES=13D4 ES=13D4 SS=13D4 CS=13D4 IP=0115 3D4:0115 895702MOUBX+02,DXBP=0000 SI=0200 DI=0204 NU UP EI PL NZ AC PE CDS:020A=0000C:INDOSsysteB32cBd.exe - debug3D4:0100 nou13D4:0103 nou 13D4:0106 mou 13D4:0109 mou3D4:010B mou3D4:010E a
39、dd 13D4:0110 adc 13D4:0113 nou23D4:0115 mou13D4:0118 -g =100 0115ax,si dx,si+2 ax.di dx.Ldi+2 bx j.ax bx+2,dx附加题:c:( C: I!TOOSsyst eB32cBd. exe - debug3D4:0119 L3D4:011D3D4:0120 3D4:0122 3D4:0124 3D4:0126 3D4:0128 3D4:012C 3D4:012E 3D4:0131-g =01003D4:0119 L3D4:011D3D4:0120 3D4:0122 3D4:0124 3D4:012
40、6 3D4:0128 3D4:012C 3D4:012E 3D4:0131-g =01003D4:0119 L3D4:011D3D4:0120 3D4:0122 3D4:0124 3D4:0126 3D4:0128 3D4:012C 3D4:012E 3D4:0131-g =0100nou nou sub sbb mou nou mou idiu mouXXX X0 8 0 adbd 0 * X 0 X X X X X Xb0 cb c a cb 0131X=0002 S=13D4 3D4:0131-d 00003D4:0000 3D4:0010 3D4:0020 3D4:0030 3D4:0
41、040 3D4:0050 3D4:00603D4:0070BX=021CES=13D400002EF20100 00F10222C8F85D00 13FF0C22CX=0000 DX=0001 SP=FFEE SS=13D4 CS=13D4 IP=0131 ADD BX+SI,ALF1FF0000 40FF000001FF000000FF00008CF40000 31FD0022FEF00000F0F00022F8F80000F3F1002203F0000000F00022 17F40B0001F10C22BP=0000 SI=0000 DI=0000NU UP EI NG NZ AC PE CDS:021C=0030FF000000FF000082B0000030B00000EFD000000F000220AFE000008F4002203F1000000F0002202.DOS BOXDOSBox 0.74, Cpu speed: 3000 cycles. Frameskip 0, Program: DEBUGZ:mountCurrent mounted drives are:Drive Z is mounted as Internal Uirt
限制150内