实验四 子程序设计和调用

上传人:第*** 文档编号:35406608 上传时间:2018-03-15 格式:DOC 页数:7 大小:84KB
返回 下载 相关 举报
实验四   子程序设计和调用_第1页
第1页 / 共7页
实验四   子程序设计和调用_第2页
第2页 / 共7页
实验四   子程序设计和调用_第3页
第3页 / 共7页
实验四   子程序设计和调用_第4页
第4页 / 共7页
实验四   子程序设计和调用_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《实验四 子程序设计和调用》由会员分享,可在线阅读,更多相关《实验四 子程序设计和调用(7页珍藏版)》请在金锄头文库上搜索。

1、实验四 子程序设计和调用 一、实验目的 1) 学习子程序的定义和调用方法。 2) 掌握子程序设计、编制及调试。 二、实验内容 编写计算 N 个偶数之和的子程序和接收键入的 N 及将结果送显示器的主程 序。三、实验准备 1) 阅读教材中有关的内容,按要求编写程序。 2) 熟悉字符显示程序段的编写。 四、实验设备 PC 机一台 五、实验步骤 1) 编辑、调试。 2) 运行EXE 文件并进行调试。六、实验报告的要求 1) 列出源程序。 stack segment stack stackdw 32 dup(?)stack endsdata segmentinput db please input N:

2、 ,$n db 6,0,6 dup(?)obf db 9 dup(?)data endscode segmentbegin proc farassume ss:stack,cs:code,ds:datapush dssub ax,axpush axmov ax, datamov ds, axmov dx,offset inputmov ah,9int 21hmov dx,offset nmov ah,10int 21hmov si,offset n+2mov cl,n+1mov ch,0call abccall sumshl ax,1mov bx,seg obfmov es,bxmov di,

3、offset obf+1call cbacall lfmov dx,offset obfmov ah,9int 21hretbegin endPsum procpush cxpush bx;加入你的程序,ax 为出口mov cx,axmov bx,0mov ax,bxzx: add bx,1add ax,bxloop zxpop bxpop cxretsum endpabc procmov ax,0abc1: push cxmov cx,10mul cxand byte ptrsi,0fhadd al,siadc ah,0inc sipop cxloop abc1retabc endpcba

4、procpush axpush bxpush cxpush ush dior ax,axjns plusmov byte ptr es:di,-inc dineg axplus: mov cx,0mov bx,10lop1: mov dx,0div bxpush dxinc cxor ax,axjnz lop1lop2: pop axadd al,30hstosbloop lop2mov al,$stosbpop dipop op cxpop bxpop axretcba endpLF PROCMOV DL,0AHMOV AH,2INT 21HMOV DL,0DHMOV AH,2INT 21H

5、RETLF ENDPcode endsend begin2) 写出调试结果。七、思考题七、思考题要计算 N 个自然数之和,程序如何改写?;请N个偶数之和方法1stack segment stack stackdw 32 dup(?)stack endsdata segmentinput db please input N: ,$n db 6,0,6 dup(?)obf db 9 dup(?)data endscode segmentbegin proc farassume ss:stack,cs:code,ds:datapush dssub ax,axpush axmov ax, datamo

6、v ds, axmov dx,offset inputmov ah,9int 21hmov dx,offset nmov ah,10int 21hmov si,offset n+2mov cl,n+1mov ch,0call abccall sumshl ax,1mov bx,seg obfmov es,bxmov di,offset obf+1call cbacall lfmov dx,offset obfmov ah,9int 21hretbegin endPsum procpush cxpush bx;加入你的程序,ax为出口pop bxpop cxretsum endpabc proc

7、mov ax,0abc1: push cxmov cx,10mul cxand byte ptrsi,0fhadd al,siadc ah,0inc sipop cxloop abc1retabc endpcba procpush axpush bxpush cxpush ush dior ax,axjns plusmov byte ptr es:di,-inc dineg axplus: mov cx,0mov bx,10lop1: mov dx,0div bxpush dxinc cxor ax,axjnz lop1lop2: pop axadd al,30hstosbloop lop2m

8、ov al,$stosbpop dipop op cxpop bxpop axretcba endpLF PROCMOV DL,0AHMOV AH,2INT 21HMOV DL,0DHMOV AH,2INT 21HRETLF ENDPcode endsend begin奇数求和stack segment stack stackdw 32 dup(?)stack endsdata segmentinput db please input N: ,$n db 6,0,6 dup(?)obf db 9 dup(?)data endscode segmentbegin proc farassume s

9、s:stack,cs:code,ds:datapush dssub ax,axpush axmov ax, datamov ds, axmov dx,offset inputmov ah,9int 21hmov dx,offset nmov ah,10int 21hmov si,offset n+2mov cl,n+1mov ch,0call abccall summov bx,seg obfmov es,bxmov di,offset obf+1call cbacall lfmov dx,offset obfmov ah,9int 21hretbegin endPsum procpush c

10、xpush bx;加入你的程序,ax为出口mov cx,axmov ax,0mov bx,1next: add ax,bxadd bx,2loop nextpop bxpop cxretsum endpabc procmov ax,0abc1: push cxmov cx,10mul cxand byte ptrsi,0fhadd al,siadc ah,0inc sipop cxloop abc1retabc endpcba procpush axpush bxpush cxpush ush dior ax,axjns plusmov byte ptr es:di,-inc dineg axplus: mov cx,0mov bx,10lop1: mov dx,0div bxpush dxinc cxor ax,axjnz lop1lop2: pop axadd al,30hstosbloop lop2mov al,$stosbpop dipop op cxpop bxpop axretcba endpLF PROCMOV DL,0AHMOV AH,2INT 21HMOV DL,0DHMOV AH,2INT 21HRETLF ENDPcode endsend begin

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号