收藏 分享(赏)

汇编第六章答案.doc

上传人:精品资料 文档编号:10587455 上传时间:2019-12-02 格式:DOC 页数:25 大小:150KB
下载 相关 举报
汇编第六章答案.doc_第1页
第1页 / 共25页
汇编第六章答案.doc_第2页
第2页 / 共25页
汇编第六章答案.doc_第3页
第3页 / 共25页
汇编第六章答案.doc_第4页
第4页 / 共25页
汇编第六章答案.doc_第5页
第5页 / 共25页
点击查看更多>>
资源描述

1、第六章答案=1.下面的程序段有错吗?若有,请指出错误.CRAY PROCPUSH AXADD AX,BXRETENDP CRAY解:当然有错误,ENDP CRAY 写反了,应该将其改成 CRAY ENDP.2.已知堆栈寄存器 SS的内容是 0F0A0H,堆栈指示器 SP的内容是 00B0H,先执行两条把 8057H和 0F79BH分别入栈的 PUSH指令.然后再执行一 POP指令.试画出示意图说明堆栈及 SP内容的变化过程.3.分析下面“6,3 的程序“,画出堆栈最满时各单元的地址及内容.; 6.3题的程序;=S_SEG SEGMENT AT 1000H ;DEFINE STACK SEGME

2、NTDW 200 DUP(?)TOS LABEL WORDS_SEG ENDSC_SEG SEGMENT ;DEFINE CODE SEGMENTASSUME CS:C_SEG,SS:S_SEGMOV AX,S_SEGMOV SS,AXMOV SP,OFFSET TOSPUSH DSMOV AX,0PUSH AX.PUSH T_ADDRPUSH AXPUSHF.POPFPOP AXPOP T_ADDRRETC_SEG ENDS ;END OF CODE SEGMENTEND C_SEG ;END OF ASSEMBLY4.分析下面“6.4 题的程序“的功能,写出堆栈最满时各单元的地址及内容.;

3、 6.4题的程序;=STACK SEGMENT AT 500HDW 128 DUP(?)TOS LABEL WORDSTACK ENDSCODE SEGMENT ;DEFINE CODE SEGMENTMAIN PROC FAR ;MAIN PART OF PROGRAMASSUME CS:CODE,SS:STACKSTART: ;STARTING EXECUTION ADDRESSMOV AX,STACKMOV SS,AXMOV SP,OFFSET TOSPUSH DSSUB AX,AXPUSH AX;MAIN PART OF PROGRAM GOES HEREMOV AX,4321HCAL

4、L HTOARET ;RETURN TO DOSMAIN ENDP ;END OF MAIN PART OF PROGRAMHTOA PROC NEAR ;DEFINE SUBPROCEDURE HTOACMP AX,15JLE B1PUSH AXPUSH BPMOV BP,SPMOV BX,BP+2AND BX,000FHMOV BP+2,BXPOP BPMOV CL,4SHR AX,CLCALL HTOAPOP AXB1:ADD AL,30HCMP AL,3AHJL PRINTITADD AL,07HPRINTIT:MOV DL,ALMOV AH,2INT 21HRETHTOA ENDP

5、;END OF SUBPROCEDURECODE ENDS ;END OF CODE SEGMENTEND START ;END OF ASSEMBLY5.下面是 6.5题的程序清单,请在清单中填入此程序执行过程中的堆栈变化.0000 STACKSG SEGMENT0000 20 . DW 32 DUP(?)?0040 STACKSG ENDS0000 CODESG SEGMENT PARA CODE0000 BEGIN PROC FARASSUME CS:CODESG,SS:STACKSG0000 1E PUSH DS0001 2B C0 SUB AX,AX0003 50 PUSH AX00

6、04 E8 0008 R CALL P100007 CB RET0008 BEGIN ENDP0008 B10 PROC0008 E8 000C R CALL C10000B C3 RET000C B10 ENDP000C C10 PROC000C C3 RET000D C10 ENDP000D CODESG ENDSEND BEGIN6.写一段子程序 SKIPLINES,完成输出空行的功能.空行的行数在 AX寄存器中.解:SKIPLINES PROC NEAR PUSH CX PUSH DX MOV CX,AX NEXT: MOV AH,2 MOV DL,0AH INT 21H MOV AH

7、,2 MOV DL,0DH INT 21H LOOP NEXT POP DX POP CX RET SKIPLINES ENDP7.设有 10个学生的成绩分别是 76,69,81,90,73,88,99,63,100和 80分.试编制一个子程序统计 60-69,70-79,80-89,90-99和 100分的人数并分别存放到S6,S7,S8,S9和 S10单元中.DSEG SEGMENT NUM DW 76,69,84,90,73,88,99,63,100,80 N DW 10 S6 DW 0 S7 DW 0 S8 DW 0 S9 DW 0 S10 DW 0 DSEG ENDS CODE SE

8、GMENT MAIN PROC FAR ASSUME CS:CODE, DS:DSEG START: PUSH DS SUB AX, AX PUSH AX MOV AX, DSEG MOV DS, AX CALL SUB1 RET MAIN ENDP SUB1 PROC NEAR PUSH AX PUSH BX PUSH CX PUSH SI MOV SI, 0 MOV CX, N NEXT: MOV AX, NUMSI MOV BX, 10 DIV BL MOV BL, AL CBW SUB BX, 6 SAL BX, 1 INC S6BX ADD SI,2 LOOP NEXT POP SI

9、 POP CX POP BX POP AX RET SUB1 ENDP CODE ENDS END START (解法二)datasg segmentgrade db 76,69,84,90,73,88,99,63,100,80s6 db 0s7 db 0s8 db 0s9 db 0s10 db 0mess6 db 6069:$mess7 db 7079:$mess8 db 8089:$mess9 db 9099:$mess10 db 100:$datasg endscodesg segmentmain proc farassume cs:codesg,ds:datasgstart:push

10、dssub ax,axpush axmov ax,datasgmov ds,axcall sub1lea dx,mess6call dispstrmov dl,s6call dispscorecall crlflea dx,mess7call dispstrmov dl,s7call dispscore call crlflea dx,mess8call dispstrmov dl,s8call dispscorecall crlflea dx,mess9call dispstrmov dl,s9call dispscore call crlflea dx,mess10call dispstr

11、mov dl,s10call dispscore call crlfretmain endpsub1 proc nearmov cx,10mov si,0loop1: mov al,gradesicmp al,60jl next5cmp al,70jge next1inc s6jmp short next5next1: cmp al,80jge next2inc s7jmp short next5next2: cmp al,90jge next3inc s8jmp short next5next3: cmp al,100jg next5je next4inc s9jmp short next5

12、next4: inc s10next5: inc siloop loop1retsub1 endpdispstr proc nearmov ah,9int 21hdispstr endpdispscore proc nearadd dl,30hmov ah,2int 21hdispscore endpcrlf proc nearmov dl,0dhmov ah,2int 21hmov dl,0ahmov ah,2int 21hretcrlf endpcodesg endsend start8.编写一个有主程序和子程序结构的程序模块.子程序的参数是一个 N字节数组的首地址 TABLE,数 N及字

13、符 CHAR.要求在 N字节数组中查找字符 CHAR,并记录该字符的出现次数.;主程序则要求从键盘接收一串字符以建立字节数组 TABLE,并逐个显示从键盘输入的每个字符 CHAR以及它在 TABLE数组中出现的次数.(为简化起见,假设出现次数=15,可以用十六进制形式显示出来)解:DATA SEGMENT MAXLEN DB 40 N DB ? TABLE DB 40 DUP (?) CHAR DB A ; 查找字符A EVEN _ADDR DW 3 DUP(?) DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA MAIN PROC FAR STAR

14、T: PUSH DS MOV AX, 0 PUSH AX MOV AX, DATA MOV DS, AX LEA DX, MAXLEN MOV AH, 0AH INT 21H ; 从键盘接收字符串 MOV _ADDR, OFFSET TABLE MOV _ADDR+2, OFFSET N MOV _ADDR+4, OFFSET CHAR MOV BX, OFFSET _ADDR ; 通过地址表传送变量地址 CALL COUNT ; 计算 CHAR的出现次数 CALL DISPLAY ; 显示 RET MAIN ENDPCOUNT PROC NEAR ; COUNT子程序 PUSH SI PUS

15、H DI PUSH AX PUSH CX MOV DI, BX MOV SI, BX+2 MOV CL, BYTE PTRSI MOV CH, 0 MOV SI, BX+4 MOV AL, BYTE PTRSI MOV BX, 0 AGAIN: CMP AL, BYTE PTRDI JNE L1 INC BX L1: INC DI LOOP AGAIN POP CX POP AX POP DI POP SI RET COUNT ENDP DISPLAY PROC NEAR ; DISPLAY子程序 CALL CRLF ; 显示回车和换行 MOV DL, CHAR MOV AH, 2 INT 2

16、1H MOV DL, 20H MOV AH, 2 INT 21H MOV AL, BL AND AL, 0FH ADD AL, 30H CMP AL, 3AH JL PRINT ADD AL, 7 PRINT: MOV DL, AL INT 21H CALL CRLF RET DISPLAY ENDP CRLF PROC NEAR ; CRLF子程序 MOV DL, 0DH MOV AH, 2 INT 21H MOV DL, 0AH MOV AH, 2 INT 21H RET CRLF ENDP CODE ENDS END START9.编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及

17、8个字符的电话号码,并以一定的格式显示出来.主程序 TELIST:(1)显示提示符 INPUT NAME:;(2)调用子程序 INPUT_NAME输入姓名:(3)显示提示符 INPUT A TELEPHONE NUMBER:;(4)调用子程序 INPHONE输入电话号码;(5)调用子程序 PRINTLINE显示姓名及电话号码;子程序 INPUT_NAME:(1)调用键盘输入子程序 GETCHAR,把输入的姓名存放在 INBUF缓冲区中;(2)把 INBUF中的姓名移入输出行 OUTNAME;子程序 INPHONE:(1)调用键盘输入子程序 GETCHAR,把输入的 8位电话号码存放在 INBU

18、F缓冲区中;(2)把 INBUF中的号码移入输出行 OUTPHONE.子程序 PRINTLINE:显示姓名及电话号码,格式为:NAME TEL* *=;编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及 8个字符的电话号码,并以一定的格式显示出来(解法一)data segmentNo_of_name db 20No_of_phone db 8inbuf db 20 dup(?) outname db 20 dup(?),$outphone db 8 dup(?),$message1 db please input name:,$message2 db please input a tele

19、phone number:,$message3 db NAME,16 dup(20h),TEL.,13,10,$errormessage1 db you should input 8 numbers!,13,10,$errormessage2 db you input a wrong number!,13,10,$flag db ?data endsprog segmentmain proc farassume cs:prog,ds:datastart:push dssub ax,axpush axmov ax,datamov ds,axmov flag,0lea dx,message1mov

20、 ah,09int 21hcall input_namecall crlflea dx,message2mov ah,09int 21hcall inphonecall crlfcmp flag,1je exitcall printlineexit:retmain endpinput_name proc nearpush axpush dxpush cxmov cx,0mov cl,No_of_namecall getcharmov ax,0mov al,No_of_namesub ax,cxmov cx,axmov si,0next1: mov al,inbufsimov outnamesi

21、,alinc siloop next1pop cxpop dxpop axretinput_name endpinphone proc nearpush axpush dxmov cx,0mov cl,No_of_phonecall getcharcmp cx,0jnz error1mov cl,No_of_phone mov si,0next2: mov al,inbufsicmp al,30hjl error2cmp al,39hja error2mov outphonesi,alinc siloop next2jmp exit2error1:call crlflea dx,errorme

22、ssage1mov ah,09int 21hmov flag,1jmp exit2error2: call crlflea dx,errormessage2mov ah,09int 21hmov flag,1jmp exit2exit2:pop dxpop axretinphone endpgetchar proc nearpush axpush dxmov di,0rotate:mov ah,01int 21hcmp al,0dhje exit1mov inbufdi,alinc diloop rotateexit1:pop dxpop axretgetchar endpcrlf proc

23、nearpush axpush dxmov dl,0dhmov ah,2int 21hmov dl,0ahmov ah,2int 21hpop dxpop axretcrlf endpprintline proc nearpush axpush dxlea dx,message3mov ah,09int 21hlea dx,outnamemov ah,09int 21hlea dx,outphonemov ah,09int 21hpop dxpop axretprintline endpprog endsend main=;从键盘输入姓名及 8个字符的电话号码,并以一定的格式显示出来datar

24、ea segmentinbuf label byte ;name parameter list:maxnlen db 9 ;max.lengthnamelen db ? ;no. char enterednamefld db 9 dup(?) crlf db 13,10,$messg1 db INPUT NAME:,13,10,$messg2 db INPUT A TELEPHONE NUMBER:,13,10,$messg3 db NAME TEL,13,10,$OUTNAME db 21 dup(?),$OUTPHONE db 8 dup(?),$datarea endsprognam s

25、egmentassume cs:prognam,ds:datareastart: push dssub ax,axpush axmov ax,datareamov ds,axmov es,ax TELIST proc far mov ah,09lea dx,messg1int 21hcall INPUT_NAMEmov ah,09lea dx,messg2int 21hcall INPHONEcall PRINTLINEretTELIST endpINPUT_NAME proc nearcall GETCHARmov bh,0mov bl,namelenmov cx,21sub cx,bxb2

26、0: mov namefldbx,20hinc bxloop b20lea si,namefld lea di,OUTNAMEmov cx,9cldrep movsbretINPUT_NAME endpINPHONE proc nearcall GETCHARmov bh,0mov bl,namelen mov cx,9sub cx,bxb30: mov namefld bx,20hinc bxloop b30 lea si,namefld lea di,OUTPHONEmov cx,8cldrep movsbretINPHONE endpPRINTLINE proc nearmov ah,0

27、9hlea dx,messg3int 21hmov ah,09lea dx,OUTNAMEint 21hmov ah,09lea dx,OUTPHONEint 21hretPRINTLINE endpGETCHAR proc nearmov ah,0ahlea dx,inbufint 21hmov ah,09lea dx,crlfint 21hret GETCHAR endpprognam endsend start =10.编写子程序嵌套结构的程序,把整数分别用二进制和八进制形式显示出来.主程序 BANDO:把整数字变量 VAL1存入堆栈,并调用子程序 PAIRS;子程序 PAIRS:从堆栈

28、中取出 VAL1;调用二进制显示程序 OUTBIN显示出与其等效的二进制数;输出 8个空格;调用八进制显示程序 OUTOCT显示出与其等效的八进制数;调用输出回车及换行符的子程序.model small.stack 100h.dataval1 dw 0ffffh.codemain proc farstart:push dssub ax,axpush axmov ax,datamov ds,axpush val1call pairsretmain endppairs proc nearpush bpmov bp,spmov bx,bp+4call outbinmov cx,8loop1:mov

29、dl,20hmov ah,2int 21hloop loop1call outoctcall crlfpop bpret 2pairs endpoutbin proc nearmov cx,16loop2:mov dl,0rol bx,1rcl dl,1or dl,30hmov ah,2int 21hloop loop2retoutbin endpoutoct proc nearmov dl,0rol bx,1rcl dl,1add dl,30hmov ah,2int 21hmov ch,5mov cl,3loop3:rol bx,clmov al,bland al,07hadd al,30h

30、mov dl,almov ah,2int 21hdec chjnz loop3retoutoct endpcrlf proc nearmov dl,13mov ah,2int 21hmov dl,10mov ah,2int 21hretcrlf endpend start11.假定一个名为 MAINPRO的程序要调用子程序 SUBPRO,试问:(1)MAINPRO中的什么指令告诉汇编程序 SUBPRO是在外部定义的?(2)SUBPRO怎么知道 MAINPRO要调用它?解:(1)EXTRN SUBPRO: FAR(2)PUBLIC SUBPRO12.假定程序 MAINPRO和 SUBPRO不在同

31、一模块中,MAINPRO 中定义字节变量 QTY和字变量 VALUE和 PRICE.SUBPRO程序要把 VALUE除以 QTY,并把商存在 PRICE中,试问:(1)MAINPRO怎么告诉汇编程序外部子程序要调用这三个变量?(2)SUBPRO怎么告诉汇编程序这三个变量是在另一个汇编语言程序中定义的?解:(1)PUCLIC QTY,VALUE,PRICE(2)EXTRN QTY: BYTE, VALUE: WORD, PRICE: WORD13.假设:(1)在模块 1中定义了双字变量 VAR1,首地址为 VAR2的字节数组和 NEAR标号LAB1,它们将由模块 2和模块 3所使用;(2)在模块

32、 2中定义了字变量 VAR3和 FAR标号 LAB2,而模块 1中要用到 VAR3,模块 3中要用到 LAB2;(3)在模块 3中定义了 FAR标号 LAB3,而模块 2中要用到它.试对每个源模块给出必要的 EXTRN和 PUBLIC说明.;模块 1extrn var3:wordpublic var1,var2,lab1data1 segmentvar1 dd ?var2 db 10 dup(?)data1 endscode1 segmentassume cs:code1, ds:data1main proc farmov ax,data1mov ds,ax.lab1:.mov ax,4c00

33、hint 21hmain endpcode1 endsend start;模块 2extrn var1:dword,var2:byte,lab1:near,lab3:farpublic var3,lab2data2 segmentvar3 dw ?data2 endscode2 segmentassume cs:code2, ds:data2.lab2:.code2 endsend;模块 3extrn var1:dword,var2:byte,lab1:near,lab2:farpublic lab3code3 segmentassume cs:code3.lab3:.code3 endsen

34、d14.主程序 CALLMUL定义堆栈段,数据段和代码段,并把段寄存器初始化;数据段中定义变量 QTY和 PRICE;代码段中将 PRICE装入 AX,QTY装入 BX,然后调用子程序 SUBMUL.程序 SUBMUL没有定义任何数据,它只简单地把 AX中的内容(PRICE)乘以 BX中的内容(QTY),乘积放在 DX,AX中.请编制这两个要连接起来的程序.datasg segmentqty dw 2price dw 4datasg endsstacksg segmentdw 100 dup(?)tos label wordstacksg endscodesg segmentmain proc

35、 farassume cs:codesg,ds:datasg,ss:stacksgstart:mov ax,datasgmov ds,axmov ax,stacksgmov ss,axmov sp,offset tosmov ax,pricemov bx,qtycall submulmov ax,4c00hint 21hmain endpsubmul proc nearmov dx,0mul bxretsubmul endpcodesg endsend start15.试编写一个执行以下计算的子程序 COMPUTE:R-X+Y-3其中 X,Y及 R均为字数组.假设 COMPUTE与其调用程序都

36、在同一代码段中,数据段 D_SEG中包含 X和 Y数组,数据段 E_SEG中包含 R数组,同时写出主程序调用COMPUTE过程的部分.如果主程序和 COMPUTE在同一程序模块中,但不在同一代码段中,程序就如何修改?如果主程序和 COMPUTE不在同一程序模块中,程序就如何修改?(1)d_seg segmentx dw 1y dw 4d_seg endse_seg segmentr dw ?e_seg endsc_seg segmentmain proc farassume cs:c_seg,ds:d_seg,es:e_segstart:mov ax,d_segmov ds,axmov ax,

37、e_segmov es,axcall computemov ax,4c00hint 21hmain endpcompute proc nearmov ax,xadd ax,ysub ax,3mov es:r,axretcompute endpc_seg endsend start;=(2)d_seg segmentx dw 1y dw 4d_seg endse_seg segmentr dw ?e_seg endsc_seg segmentmain proc farassume cs:c_seg,ds:d_seg,es:e_segstart:mov ax,d_segmov ds,axmov a

38、x,e_segmov es,axcall far ptr computemov ax,4c00hint 21hmain endpc_seg endsprognam segmentassume cs:prognamcompute proc farmov ax,xadd ax,ysub ax,3mov es:r,axretcompute endpprognam endsend start;=(3);模块 1extrn compute:farpublic x,y,rd_seg segmentx dw 1y dw 4d_seg endse_seg segmentr dw ?e_seg endsc_se

39、g segmentmain proc farassume cs:c_seg,ds:d_seg,es:e_segstart:mov ax,d_segmov ds,axmov ax,e_segmov es,axcall far ptr computemov ax,4c00hint 21hmain endpc_seg endsend start;模块 2extrn x:word,y:word,r:wordpublic computeprognam segmentassume cs:prognamcompute proc farmov ax,xadd ax,ysub ax,3mov es:r,axretcompute endpprognam endsend

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

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报