汇编第六章答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第六章答案=======================================1.下面的程序段有错吗?若有,请指出错误.CRAYPROCPUSHAXADDAX,BXRETENDPCRAY[解]:当然有错误,ENDPCRAY写反了,应该将其改成CRAYENDP.2.已知堆栈寄存器SS的内容是0F0A0H,堆栈指示器SP的内容是00B0H,先执行两条把8057H和0F79BH分别入栈的PUSH指令.然后再执行一POP指令.试画出示意图说明堆栈及SP内容的变化过程.3.分析下面6,3的程序,画出堆栈最满时各单元的地址及内容.;6.3题的程序;===========================================S_SEGSEGMENTAT1000H;DEFINESTACKSEGMENTDW200DUP(?)TOSLABELWORDS_SEGENDSC_SEGSEGMENT;DEFINECODESEGMENTASSUMECS:C_SEG,SS:S_SEGMOVAX,S_SEGMOVSS,AXMOVSP,OFFSETTOSPUSHDSMOVAX,0PUSHAX...PUSHT_ADDRPUSHAXPUSHF...POPFPOPAXPOPT_ADDRRETC_SEGENDS;ENDOFCODESEGMENTENDC_SEG;ENDOFASSEMBLY4.分析下面6.4题的程序的功能,写出堆栈最满时各单元的地址及内容.;6.4题的程序;====================================STACKSEGMENTAT500HDW128DUP(?)TOSLABELWORDSTACKENDSCODESEGMENT;DEFINECODESEGMENTMAINPROCFAR;MAINPARTOFPROGRAMASSUMECS:CODE,SS:STACKSTART:;STARTINGEXECUTIONADDRESSMOVAX,STACKMOVSS,AXMOVSP,OFFSETTOSPUSHDSSUBAX,AXPUSHAX;MAINPARTOFPROGRAMGOESHEREMOVAX,4321HCALLHTOARET;RETURNTODOSMAINENDP;ENDOFMAINPARTOFPROGRAMHTOAPROCNEAR;DEFINESUBPROCEDUREHTOACMPAX,15JLEB1PUSHAXPUSHBPMOVBP,SPMOVBX,[BP+2]ANDBX,000FHMOV[BP+2],BXPOPBPMOVCL,4SHRAX,CLCALLHTOAPOPAXB1:ADDAL,30HCMPAL,3AHJLPRINTITADDAL,07HPRINTIT:MOVDL,ALMOVAH,2INT21HRETHTOAENDP;ENDOFSUBPROCEDURECODEENDS;ENDOFCODESEGMENTENDSTART;ENDOFASSEMBLY5.下面是6.5题的程序清单,请在清单中填入此程序执行过程中的堆栈变化.0000STACKSGSEGMENT000020[.DW32DUP(?)????0040]STACKSGENDS0000CODESGSEGMENTPARA'CODE'0000BEGINPROCFARASSUMECS:CODESG,SS:STACKSG00001EPUSHDS00012BC0SUBAX,AX000350PUSHAX0004E80008RCALLP100007CBRET0008BEGINENDP0008B10PROC0008E8000CRCALLC10000BC3RET000CB10ENDP000CC10PROC000CC3RET000DC10ENDP000DCODESGENDSENDBEGIN6.写一段子程序SKIPLINES,完成输出空行的功能.空行的行数在AX寄存器中.[解]:SKIPLINESPROCNEARPUSHCXPUSHDXMOVCX,AXNEXT:MOVAH,2MOVDL,0AHINT21HMOVAH,2MOVDL,0DHINT21HLOOPNEXTPOPDXPOPCXRETSKIPLINESENDP7.设有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单元中.DSEGSEGMENTNUMDW76,69,84,90,73,88,99,63,100,80NDW10S6DW0S7DW0S8DW0S9DW0S10DW0DSEGENDSCODESEGMENTMAINPROCFARASSUMECS:CODE,DS:DSEGSTART:PUSHDSSUBAX,AXPUSHAXMOVAX,DSEGMOVDS,AXCALLSUB1RETMAINENDPSUB1PROCNEARPUSHAXPUSHBXPUSHCXPUSHSIMOVSI,0MOVCX,NNEXT:MOVAX,NUM[SI]MOVBX,10DIVBLMOVBL,ALCBWSUBBX,6SALBX,1INCS6[BX]ADDSI,2LOOPNEXTPOPSIPOPCXPOPBXPOPAXRETSUB1ENDPCODEENDSENDSTART(解法二)datasgsegmentgradedb76,69,84,90,73,88,99,63,100,80s6db0s7db0s8db0s9db0s10db0mess6db'60~69:$'mess7db'70~79:$'mess8db'80~89:$'mess9db'90~99:$'mess10db'100:$'datasgendscodesgsegmentmainprocfarassumecs:codesg,ds:datasgstart:pushdssubax,axpushaxmovax,datasgmovds,axcallsub1leadx,mess6calldispstrmovdl,s6calldispscorecallcrlfleadx,mess7calldispstrmovdl,s7calldispscorecallcrlfleadx,mess8calldispstrmovdl,s8calldispscorecallcrlfleadx,mess9calldispstrmovdl,s9calldispscorecallcrlfleadx,mess10calldispstrmovdl,s10calldispscorecallcrlfretmainendpsub1procnearmovcx,10movsi,0loop1:moval,grade[si]cmpal,60jlnext5cmpal,70jgenext1incs6jmpshortnext5next1:cmpal,80jgenext2incs7jmpshortnext5next2:cmpal,90jgenext3incs8jmpshortnext5next3:cmpal,100jgnext5jenext4incs9jmpshortnext5next4:incs10next5:incsilooploop1retsub1endpdispstrprocnearmovah,9int21hdispstrendpdispscoreprocnearadddl,30hmovah,2int21hdispscoreendpcrlfprocnearmovdl,0dhmovah,2int21hmovdl,0ahmovah,2int21hretcrlfendpcodesgendsendstart8.编写一个有主程序和子程序结构的程序模块.子程序的参数是一个N字节数组的首地址TABLE,数N及字符CHAR.要求在N字节数组中查找字符CHAR,并记录该字符的出现次数.;主程序则要求从键盘接收一串字符以建立字节数组TABLE,并逐个显示从键盘输入的每个字符CHAR以及它在TABLE数组中出现的次数.(为简化起见,假设出现次数=15,可以用十六进制形式显示出来)[解]:DATASEGMENTMAXLENDB40NDB?TABLEDB40DUP(?)CHARDB'A';查找字符'A'EVEN_ADDRDW3DUP(?)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXLEADX,MAXLENMOVAH,0AHINT21H;从键盘接收字符串MOV_ADDR,OFFSETTABLEMOV_ADDR+2,OFFSETNMOV_ADDR+4,OFFSETCHARMOVBX,OFFSET_ADDR;通过地址表传送变量地址CALLCOUNT;计算CHAR的出现次数CALLDISPLAY;显示RETMAINENDPCOUNTPROCNEAR;COUNT子程序PUSHSIPUSHDIPUSHAXPUSHCXMOVDI,[BX]MOVSI,[BX+2]MOVCL,BYTEPTR[SI]MOVCH,0MOVSI,[BX+4]MOVAL,BYTEPTR[SI]MOVBX,0AGAIN:CMPAL,BYTEPTR[DI]JNEL1INCBXL1:INCDILOOPAGAINPOPCXPOPAXPOPDIPOPSIRETCOUNTENDPDISPLAYPROCNEAR;DISPLAY子程序CALLCRLF;显示回车和换行MOVDL,CHARMOVAH,2INT21HMOVDL,20HMOVAH,2INT21HMOVAL,BLANDAL,0FHADDAL,30HCMPAL,3AHJLPRINTADDAL,7PRINT:MOVDL,ALINT21HCALLCRLFRETDISPLAYENDPCRLFPROCNEAR;CRLF子程序MOVDL,0DHMOVAH,2INT21HMOVDL,0AHMOVAH,2INT21HRETCRLFENDPCODEENDSENDSTART9.编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来.主程序TELIST:(1)显示提示符INPUTNAME:;(2)调用子程序INPUT_NAME输入姓名:(3)显示提示符INPUTATELEPHONENUMBER:;(4)调用子程序INPHONE输入电话号码;(5)调用子程序PRINTLINE显示姓名及电话号码;子程序INPUT_NAME:(1)调用键盘输入子程序GETCHAR,把输入的姓名存放在INBUF缓冲区中;(2)把INBUF中的姓名移入输出行OUTNAME;子程序INPHONE:(1)调用键盘输入子程序GETCHAR,把输入的8位电话号码存放在INBUF缓冲区中;(2)把INBUF中的号码移入输出行OUTPHONE.子程序PRINTLINE:显示姓名及电话号码,格式为:NAMETEL************==========================================;编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及8个字符的电话号码,并以一定的格式显示出来(解法一)datasegmentNo_of_namedb20No_of_phonedb8inbufdb20dup(?)outnamedb20dup(?),'$'outphonedb8dup(?),'$'message1db'pleaseinputname:','$'message2db'pleaseinputatelephonenumber:','$'message3db'NAME',16dup(20h),'TEL.',13,10,'$'errormessage1db'youshouldinput8numbers!',13,10,'$'errormessage2d

1 / 25
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功