中南民族大学80x86汇编实验报告.doc

上传人:仙人指路1688 文档编号:2881832 上传时间:2023-03-01 格式:DOC 页数:20 大小:276KB
返回 下载 相关 举报
中南民族大学80x86汇编实验报告.doc_第1页
第1页 / 共20页
中南民族大学80x86汇编实验报告.doc_第2页
第2页 / 共20页
中南民族大学80x86汇编实验报告.doc_第3页
第3页 / 共20页
中南民族大学80x86汇编实验报告.doc_第4页
第4页 / 共20页
中南民族大学80x86汇编实验报告.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《中南民族大学80x86汇编实验报告.doc》由会员分享,可在线阅读,更多相关《中南民族大学80x86汇编实验报告.doc(20页珍藏版)》请在三一办公上搜索。

1、院 系:计算机科学学院 专 业:计算机科学与技术年 级: 2010 级 课程名称: 汇编语言 学 号: 10061103 姓 名: 张名扬 指导教师: 雷建云 2012年 6 月 17 日年级 2010级班号 计科四班学号 10061103专业计科姓名 张名扬实验名称 计算总评成绩实验类型设计型综合型创新型实验目的或要求实验一:实验要求:从键盘中输入一同学的期中成绩,实验成绩,期末成绩和他们在总评成绩中分别占的百分比,计算得到改同学的总评成绩,并显示出来. 实验原理(算法流程) ; Example assembly language program - adds two numbers; Au

2、thor: zhang; Date: revised 7/97.386.MODEL FLATExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORDINCLUDE io.h ; header file for input/outputcr EQU 0dh ; carriage return characterLf EQU 0ah ; line feed.STACK 4096 ; reserve 4096-byte stack.DATA ; reserve storage for datagrade1 DWORD ?grade2 DWORD ?grad

3、e3 DWORD ?sum1 DWORD ?prompt1 BYTE Enter first grade: , 0prompt2 BYTE Enter the percent of first grade: , 0prompt3 BYTE Enter second grade: , 0prompt4 BYTE Enter the percent of second grade: , 0prompt5 BYTE Enter third grade: , 0prompt6 BYTE Enter the percent of third grade: , 0string BYTE 40 DUP (?

4、)label1 BYTE cr, Lf, The sum is sum BYTE 11 DUP (?) BYTE cr, Lf, 0实验原理(算法流程).CODE ; start of main program code_start: output prompt1 ; prompt for first score input string, 40 ; read ASCII characters atod string ; convert to integer mov grade1, eax ; store in memory output prompt2 ; prompt for first

5、percent input string, 40; read ASCII characters atod string; mul grade1 ; grade1*eax mov sum1,eax ; move eax to sum1output prompt3 ; input string, 40 ; atod string ; mov grade2, eax ; output prompt4 ; input string, 40; atod string; mul grade2 ; grade2*eax add sum1,eax ; add eax to sum1output prompt5

6、 ; input string, 40 ; atod string ; mov grade3, eax ; output prompt6 ; input string, 40; atod string; mul grade3 ; grade3*eax add sum1,eax ; add eax to sum1mov eax,sum1; move sum1 to eaxmov sum1,100; move 100 to sum1divsum1 ; eax/100dtoasum,eax; outputlabel1; output sum INVOKE ExitProcess, 0 ; exit

7、with return code 0PUBLIC _start ; make entry point publicEND ; end of source code实验结果分析及心得体会实验结果:成绩评定年级2010级班号 计科4班学号10061103专业计科姓名张名扬实验名称大小写字母字符互换实验类型设计型综合型创新型实验目的或要求实验二:实验要求:从键盘输入一个字符,如果该字符是回车符,直接退出程序,如果是小写字母,则转换为大写字母并显示;如果是大写字母,则转换为小写字母并显示;如果是非字母字符,则显示提示信息,并等待用户重新输入字符。实验原理(算法流程);-字母字符转换-DATAS SEG

8、MENT ;此处输入数据段代码 prompt1 db 0dh,0ah, please Input a character : ,$prompt2 db 0dh,0ah,you Input not a character ,please Input a character , $prompt3 db 0dh,0ah, uppercase letter Convert to lowercase letter: ,$prompt4 db 0dh,0ah,lowercase letter Convert to uppercase letter: ,$DATAS ENDSSTACKS SEGMENT ;

9、此处输入堆栈段代码 STACKS ENDSCODES SEGMENT ;此处输入代码段代码 ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX_input: lea dx,prompt1MOV AH,09HINT 21HMOV AH,01H INT 21HMOV BL,ALcmp BL,0dhje _end_lowcase:cmp BL,a实验原理(算法流程) jl _uppercasecmp BL,zjg _uppercaseSUB BL,20Hlea dx,prompt4MOV AH,09HINT 21HMOV D

10、L,BLMOV AH,02hINT 21Hjmp _input_uppercase:cmp BL, Ajl _warncmp BL,Zjg _warnadd BL, 20hlea dx,prompt3MOV AH,09HINT 21HMOV DL,BLMOV AH,02hINT 21Hjmp _input_warn: lea dx,prompt2MOV AH,09HINT 21H jmp _input _end: MOV AH,4CH INT 21HCODES ENDS END START实验结果分析及心得体会 成绩评定年级2010级班号 计科4班学号10061103专业计科姓名张名扬实验名称

11、显示九九乘法表实验类型设计型综合型创新型实验目的或要求实验三:实验要求:以九行九列的形式显示九九成法表 显示下三角格式也可以显示上三角格式实验原理(算法流程); Example assembly language program - adds two numbers; Author: zhang; Date: revised 7/97.386.MODEL FLATExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORDINCLUDE io.h ; header file for input/outputcr EQU 0dh ; carriage re

12、turn characterlf EQU 0ah ; line feed.STACK 4096 ; reserve 4096-byte stack.DATA ; (17)reserve storage for dataprompt BYTE -九九乘法表- , cr,lf,0row WORD 1 DUP (?)col WORD 1 DUP (?)jizhi WORD 1 DUP (?)num BYTE 6 dup(?),0 ;num作为输出的nextrow BYTE cr,lf,0mullabel BYTE *, 0equlabel BYTE =, 0.CODE ; (26)start of

13、main program code_start: output prompt; mov row,1;outloop: mov ax,row ;(30)此处要用ax寄存器 mov col,1; 实验原理(算法流程)inloop: mul col;col*al mov jizhi,ax;(33)此处要用ax寄存器 mov ax,row; itoa num,ax; output num; output mullabel; mov ax,col ; 先把col的值放到ax寄存器中去 itoa num,ax; 再把ax中的值转换为ascII值并放到num中 output num; 这里输出COL的字符形

14、式 output equlabel; mov ax,jizhi itoa num,jizhi; output num; inc col; mov ax,row;不能直接cmp col,row;因为二者都在存储器中 cmp col,ax; jle inloop; output nextrow ; inc row; cmp row,9; jle outloop; 原代码中这里和上在的跳转有错 input num,12; jmp endpro;endpro: INVOKE ExitProcess, 0 ; exit with return code 0PUBLIC _start ; make ent

15、ry point publicEND ; end of source code实验原理(算法流程)实验结果:成绩评定年级2010级班号 计科4班学号10061103专业计科姓名张名扬实验名称求给定整数的所有素因子实验类型设计型综合型创新型实验目的或要求实验四:实验要求:输入一个整数,求出所有的素因子,并表现为乘积方式,求因子的算法用子程序来实现。 实验目的:掌握子程序的原理和方法,重点掌握子程序的编写和调用的过程以及堆栈操作和参数以及全局变量的概念。实验原理(算法流程); program to get all the prime numbers of a integer; Author:zha

16、ng.MODEL FLATExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORDINCLUDE io.h ; header file for input/outputcr EQU 0dh ; carriage return characterLf EQU 0ah ; line feedMAX EQU 100 ; the max number.STACK 4096 ; reserve 4096-byte stack.DATA ; reserve storage for datanumberDWORD?indexDWORD?jDWORD?flag1BY

17、TE?flag2BYTE?prompt0BYTEPlease input an integer:,0prompt1BYTEcr,lf,cr,lf,The result is: ,0countWORD?valueBYTE11 DUP(?)BYTE0signBYTE?BYTE0.CODE ; start of main program codePROCAPROCNEAR32; 判断素数movflag1,0 ; 把0保存到flag1movindex,1 ;把1保存到index实验原理(算法流程)FORA:incindex ;dec自加mov eax,index ;将index保存到eax中去cmpe

18、ax,ecx ;让eax与ecx比较jnlENDA ;如果大于,跳转到ENDA moveax,ecxmovebx,indexCdq ;扩展被除数 divebxcmpedx,0jneFORA ;如果不相等,跳转到FORAjmpENDAA ;跳转到ENDAA ENDA:movflag1,1 ENDAA: retPROCAENDP ;子程序结束 PROCBPROCNEAR32movflag2,0MORE:cmpnumber,1jeENDBAmoveax,numbercdqdivindexcmpedx,0jneENDBBmovnumber,eaxinccountcmpcount,1jePRINTNmo

19、vsign,*outputsignPRINTN:dtoavalue,indexcallPROCCjmpMOREENDBA:movflag2,1ENDBB:retPROCBENDP实验原理(算法流程)PROCCPROCNEAR32leaebx,valueWHILEA:moval,byte ptr ebxincebxcmpal,0jeENDCcmpal,20hjeWHILEAmovsign,aloutputsignjmpWHILEAENDC:retPROCCENDP_start:outputprompt0;主函数开始inputvalue,11outputprompt1movsign,=output

20、valueoutputsignatodvaluemovnumber,eaxmovcount,0movj,1NF1:incjmovecx,jcallPROCAcmpflag1,1jneNF1callPROCBcmpflag2,1jneNF1 ENDFILE: INVOKE ExitProcess, 0 ; exit with return code 0PUBLIC _start ; make entry point publicEND (写不完时,可另加附页。)实验结果分析及心得体会成绩评定教师签名: 年 月 日年级 2010级班号 计科4班学号 10061103专业计科姓名 张名扬实验名称字符

21、串中指定字符的替换实验类型设计型综合型创新型实验目的或要求实验五:实验要求:输入一个字符实现替换功能将字符串中所有的A替换成a并输出新产生的字符串实验原理(算法流程)算法如下:; This program is to get the letter before and after the one you put in; Author: xiang shiyuan.386.MODEL FLATExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORDINCLUDE io.h ; header file for input/outputcr EQU 0dh

22、 ; carriage return characterLf EQU 0ah ; line feed.STACK 4096 ; reserve 4096-byte stack.DATA ; reserve storage for dataprompt1 BYTE This programe will exchange A to a BYTE Please input string: ,0prompt2 BYTE The result is: string BYTE 50 DUP(?).CODE ; start of main program code_start: output prompt1

23、 ;prompt1是A替换a并输出所在的串 input string,50 ; read ASCII characters lea ebx,string ;find length of string)实验原理(算法流程)a: cmp byte ptr ebx,0dh ;串中每个字符与回车字符比较 je end1 ;等于则输出结果 cmp byte ptr ebx,41h ;串中每个字符与A字符的比较 je change ;相等则转换b: inc ebx ;继续比较下一个字符 jmp a change: mov byte ptr ebx,61h ;转换为a jmp b end1: output

24、prompt2 ;输出结果 INVOKE ExitProcess, 0 ; exit with return code 0PUBLIC _start ; make entry point public END ;end of source code 实验结果分析及心得体会实验结果:成绩评定年级2010级班号计科4班学号10061103专业计科姓名张名扬实验名称使用位操作指令实现双字类型数的高低字转换实验类型设计型综合型创新型实验目的或要求实验六:实验目的:掌握位指令的使用。实验要求:EAX寄存器中的数,设法将其高字和低字实现互换实验原理(算法流程) ; Author: zhang ; Date

25、: revised 10/2008.386.MODEL FLATExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORDINCLUDE io.hcr EQU 0dh Lf EQU 0ah.STACK 4096.DATAprompt BYTE Input a number: ,0number BYTE 20 dup (?)result BYTE cr,Lf,The 2s complement representation is: hexout BYTE 8 DUP(?),cr,Lf,0prompt2 BYTE After the shift ,cr,l

26、f,0.CODEHex PROC NEAR32 ; Hex sub: output of a 16-digit hexadecimal number push eax lea ebx,hexout+7 mov ecx,8 mov esi,eax forcount: mov edx,eax and edx,0000000fh ; 28 figures on the left side of Clear, and the remaining unchanged cmp edx,9 jnle elseLetter or edx,30h ; Converted to ASCII code jmp en

27、difDigitelseLetter:add edx,A-10 ; Converted to letters 实验原理(算法流程)endifDigit: mov BYTE PTR ebx,dl dec ebx shr eax,4 ;右移位 loop forcount output result pop eax retHex ENDP_start: output prompt input number,16 ;输入一个数字 atod number call Hex ;调用子程序Hex rol eax,16 ;循环左移位 output prompt2 ;输出转换后的十六进制数 call Hex INVOKE ExitProcess, 0 PUBLIC _start END 实验结果分析及心得体会成绩评定教师签名: 年 月 日

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号