您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 微计算机原理第二版潘名莲习题答案4_8之后
4-8试定义一个结构,它应包括一个学生的下列信息:姓名、学号及三门课程的成绩。然后给出3条结构预置语句,将3个学生的情况送入3个结构变量中。解:DATASEGMENTSTUDENTSTRUCNAMEDB‘abcd’NODB?ENGDB?MATDB?PHYDB?STUDENTENDSS1STUDENT‘ZHAN’,20H,78H,95H,80HS2STUDENT‘WANG’,21H,88H,91H,90HS3STUDENT‘LILI’,22H,79H,75H,70HDATAENDS4-9试定义一条宏指令,它可以实现任一数据块的传送(假设无地址重叠),源地址、目的地址和块长度作为参数处理。MOVDATAMACROSN,DN,CNCLDMOVSI,OFFSETSNMOVDI,OFFSETDNMOVCX,CNREPMOVSDN,SNENDM4-10设VAR1和VAR2为字变量,LAB为标号,试指出下列指令的错误,并改正之。(1)ADDVAR1,VAR2(无两内存单元加法指令)(2)SUBAL,VAR1(字节变量不能和字变量直接相加)(3)JMPLAB[SI](标号不是立即数)(4)JNZVAR1(不是程序标号)(5)JMPNEARLAB(同3)(6)MOVAL,VAR2(AL不能存字变量)解:(1)MOVAX,VAR1(2)MOVAH,0(3)JMPOFFSETLAB[SI]ADDAX,VAR2SUBAX,VAR1(4)MOVSI,VAR1(5)JMPNEARPTRLAB(6)MOVAX,VAR2JNZTARGET……TARGET:JMP[SI]4-11已知数据定义如下,问L1和L2等于多少?B1DB1,2,3,’123’B2DB0L1EQU$-B1L2EQUB2-B1解:$=7,∴$-B1=7-0=7即L1等于7L2=B2的偏移地址6-B1的偏移地址0=64-15用查表法将存放于数据段中的一个有序的十六进制数串(范围:0~FH)翻译成ASCII码表仍放于数据段中。解:DATASEGMENTXDHEXDB0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15TBASCIIDB‘0123456789ABCDEF’DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVCX,16MOVSI,OFFSETXDHEXMOVBX,OFFSETTBASCIIMOVAH,0AGAIN:MOVAL,[SI]MOVDI,AXMOVAL,[BX+DI]MOV[SI],ALINCSILOOPAGAINRETMAINENDPCODEENDSENDSTART4-16试编写一程序,把X和Y中的大者存于BIG单元,若X=Y,则把其中之一存入BIG单元。解:DATASEGMENTXDW?YDW?BIGDW?DATAENDS;------------------------------CODESEGMENTASSUMECS:CODE,DS:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVAX,XCMPAX,YJNCSTOBIG;无符号数判断,有符号数用JGEMOVAX,YSTOBIG:MOVBIG,AXRETMAINENDPCODEENDSENDMAIN4-17试编写一程序,比较两个字符串STRING1和STRING2所含字符是否完全相同,若相同显示“MATCH”,反之,则显示“NOMATCH”。解:DATASEGMENTSTRING1DB50DUP(?)STRING2DB50DUP(?)MATDB‘MATCH$’NMATDB‘NOMATCH$’DATAENDS;------------------------------CODEEGMENTASSUMECS:CODE,DS:DATA,ES:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AXMOVCX,LENGTHSTRING1LEASI,STRING1LEADI,STRING2LEADX,MATCLDREPECMPSBJEPLAYLEADX,NOMATPLAY:MOVAH.09INT21HRETMAINENDPCODEENDSENDMAIN4-19假设已编好5个乐曲程序,它们的入口地址(含段首址和偏移地址)存放在数据段中的跳越表MUSICTAB中。试编写一个管理程序,其功能是:根据键盘输入的乐曲编号00~04转到所点乐曲入口,执行乐曲程序。解:DATASEGMENTMUSICTABDWOFFSETMUSIC0,SEGMUSIC0DWOFFSETMUSIC1,SEGMUSIC1DWOFFSETMUSIC2,SEGMUSIC2DWOFFSETMUSIC3,SEGMUSIC3DWOFFSETMUSIC4,SEGMUSIC4DATAENDS;------------------------------CODEEGMENTASSUMECS:CODE,DS:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AX;---------------------------------------------------------------KEYIN:MOVAH,1INT21HSUBAL,30HMOVCL,4ROLAL,CLMOVBL,ALMOVAH,1INT21HSUBAL,30HADDAL,BLMOVAH,0ADDAX,AXADDAX,AXLEABX,MUSICTABMOVSI,AXJMPDWORDPTR[BX][SI];见教科书116页,④段间间接寻址MUSIC0:…MUSIC1:…MUSIC2:…MUSIC3:…MUSIC4:…EXIT:RETMAINENDPCODEENDSENDMAIN4-21在数据段中存有一字符串(≤80个字符),以回车CR结束。编一程序统计此字符串的长度,并将它存入数据区LENTH单元,也显示在屏幕上。解:设字符串为STRING字节单元开始,程序采用DO_WHILE的循环结构,CX寄存器用作字符串长度计数。循环结束条件两个:(1)找到CR,屏幕上显示字符串长度-LENTH。(2)未找到CR,屏幕上显示“ERROR”。DATASEGMENTSTRINGDB'12345678'DB0DHDB71DUP(?)LENTHDB?ERRDB'ERROR$'DATAENDS;-------------------------------------CODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATAMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AX;-------------------------------------------------MOVDI,OFFSETSTRINGCLDMOVCX,80MOVAL,0DHREPNZSCASBJNZPLAYERMOVAX,80SUBAX,CXMOVCL,10DIVCLMOVDL,ALORDL,30HPUSHAXMOVAH,2INT21HPOPAXMOVDL,AHORDL,30HMOVAH,02INT21HRETPLAYER:MOVDX,OFFSETERRMOVAH,9INT21HRET;----------------------------------------------------MAINENDPCODEENDSENDMAIN4-22试用串操作指令将一个数组BLOCK(均为字节数)中的奇数和偶数分开存放。解:1设数组BLOCK在数据段,程序运行后把数组中的奇数存放在数据段数组PODATA、偶数存放在数据段数组PEDATA中。2程序分两次扫描,第一次搜索奇数,并存放于PODATA中、第二次搜索偶数,并存放于PEDATA中。3两次搜索均用FOR语句结构。DATASEGMENTBLOCKDB1,2,3,4,5,6,7,8,9,90,21,33COUNTEQU$-BLOCKPODATADBCOUNTDUP(?)PEDATADBCOUNTDUP(?)DATAENDS;---------------------------------CODESEGMENTMAINPROCFARASSUMECS:CODE,DS:DATA,DS:DATASTART:PUSHDSMOVAX,0PUSHAXMOVAX,DATAMOVDS,AXMOVES,AX;---------------------------------MOVSI,OFFSETBLOCKMOVDI,OFFSETPODATAMOVCX,COUNTAGAIN:LOADSBTESTAL,1JZELOPSTOSBELOP:LOOPAGAIN;---------------------------------MOVSI,OFFSETBLOCKMOVDI,OFFSETPEDATAMOVCX,COUNTAGAIN1:LOADSBTESTAL,1JNZELOP1STOSBELOP1:LOOPAGAIN1;----------------------------RET;----------------------------MAINENDPCODEENDS;----------------------------ENDMAIN4-23编一个程序,其功能是将一个字数组ARRAY中的正数和负数分开存放于以PLUS和MINNUS开始的单元中,并在屏幕上显示出正数和负数的个数。设该数组长度放在数组的第一个字单元中。解:①搜索采用FOR语句结构循环程序。②程序每次循环采用正负数分支完成该次正数与负数分离存储。DATASEGMENTARRAYDW10H,8DUP(1FH,-12)PLUSDW8DUP(?,?)MINUSDW8DUP(?,?)DATAENDS;--------------------------------CODESEGMENTASSUMECS:CODE,DS:DATAMAINPROCFARSTART:PUSHDSXORAX,AXPUSHAXMOVAX,DATAMOVDS,AXMOVES,AX;--------------------------------MOVSI,OFFSETARRAYMOVDI,OFFSETPLUSMOVBX,OFFSETMINUSLODSWMOVCX,AXAGAIN:LODSWTESTAX,8000HJNZMINSPLS:STOSWLOOPAGAINMINS:XCHGBX,DISTOSWXCHGBX,DILOOPAGAINSUBDI,OFFSETPLUSSHRDI,1SUBBX,OFFSETMINUSSHRBX,1MOVAX,DIMOVCL,10DIVCLORAL,30HORAH,30HMOVDL,ALPUSHAXMOVAH,2INT21HPOPAXMOVDL,AHMOVAH,2INT21HMOVDL,0DHMOVAH,2INT21HMOVDL,0AHINT21HMOVAX,BXMOVCL,10DIVCLORAL,30HORAH,30HMOVDL,ALPUSHAXMOVAH,2INT21HPOPAXMOVDL,AHMOVAH,2INT21HMOVDL,0DHMOVAH,2INT21HRET;-----------------------MAINENDPCODEENDSENDMAIN4-24现有一组无序的字:25,46,3,75,-5,30,要求对它们进行排序,其算法如图4-31所示。试编写完成此功能的程序。解:DATASEGMENTARRAYDW25,46,3,75,-5,30COUNTEQU$-ARRAYDATAE
本文标题:微计算机原理第二版潘名莲习题答案4_8之后
链接地址:https://www.777doc.com/doc-2471696 .html