_微机原理第四五六章作业

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

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

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

资源描述

第四章作业答案4.1分析汇编语言源程序应该由哪些逻辑段组成?各段的作用是什么?语句标号和变量应具备哪3种属性?【解答】汇编语言源程序应该由若干个逻辑段组成,可以有若干个数据段、代码段、堆栈段和附加数据段,至少要有一个代码段。各段的作用如下:(1)代码段用来存放程序和常数。(2)数据段用于数据的保存。(3)堆栈段用于保护数据,尤其在子程序调用、中断过程中进行现场信息保护。(4)附加数据段用于数据的保存。语句标号和变量应具备的3种属性:段属性、偏移属性和类型属性。4.2指出下列程序中的错误:STAKSGSEGMENTDB100DUP(?)STA_SGENDSDTSEGSEGMENTDATA1DB?DTSEGENDCDSEGSEGMENTMAINPROCFARSTART:MOVDS,DATSEGMOVAL,34HADDAL,4FHMOVDATA,ALSTARTENDPCDSEGENDSEND答案:改正后:STAKSGSEGMENTDB100DUP(?)STAKSGENDSDTSEGSEGMENTDATA1DB?DTSEGENDSCDSEGSEGMENTMAINPROCFARASSUMECS:CDSEG,DS:DTSEG,SS:STAKSGSTART:MOVAX,DTSEGMOVDS,AXMOVAL,34HADDAL,4FHMOVDATA1,ALMOVAH,4CHINT21HMAINENDPCDSEGENDSENDS4.3.将下列文件类型填入空格:(1).obj(2).exe(3).crf(4).asm(5).lst(6).map编辑程序输出的文件有________________;汇编程序输出的文件有________________;连接程序输出的文件有________________。答案:编辑程序输出文件:(4)汇编程序输出文件:(1),(3),(5)连接程序输出文件:(2),(6)4.4下面的数据项定义了多少个字节?DATA_1DB6DUP(4DUP(0FFH))答案:24字节4.5.对于下面两个数据段,偏移地址为10H和11H的两个字节中的数据是一样的吗?为什么?DTSEGSEGMENT|DTSEGSEGMENTORG10H|ORG10HDATA1DB72H|DATA1DW7204HDB04H|DTSEGENDSDTSEGENDS|答案:不一样.分别是72H,04H和04H,72H.存储字时低8位存在低字节,高8位存在高字节.4.6.下面的数据项设置了多少个字节?(1)ASC_DATADB'1234'(2)HEX_DATADB1234H答案:(1)设置了4个字节(2)设置了2个字节4.7.执行下列指令后,AX寄存器中的内容是什么?TABLEDW10,20,30,40,50ENTRYDW3...MOVBX,OFFSETTABLEADDBX,ENTRYMOVAX,[BX]答案:(AX)=404.8.分析下列程序的功能,写出堆栈最满时各单元的地址及内容。SSEGSEGMENT'STACK'AT1000H;堆栈的段地址为1000HDW128DUP(?)TOSLABELWORDSSEGENDS;-------------------------------------------DSEGSEGMENTDW32DUP(?)DSEGENDS;-------------------------------------------CSEGSEGMENTMAINPROCFARASSUMECS:CSEG,DSSEG,SS:SSEGSTART:MOVAX,SSEGMOVSS,AXMOVAX,DSEGMOVDS,AXMOVAX,4321HCALLHTOARETN:MOVAH,4CHINT21HMAINENDP;-------------------------------------------HTOAPROCNEARCMPAX,15JLEB1PUSHAXPUSHBPMOVBP,SPMOVBX,[BP+2]ANDBX,0FHMOV[BP+2],BXPOPBPMOVCL,4SHRAX,CLCALLHTOAB1:POPAXB2:ADDAL,30HJLPRTADDAL,07PRT:MOVDL,ALMOVAH,2INT21HRETHTOAENDPCSEGENDS;;-----------------------------------------ENDSTART答案:1000:0F2HB11000:0F4H31000:0F6HB11000:0F8H21000:0FAHB11000:0FCH11000:0FEHRETN1000:100H4.9下面是将内存一字节数据高4位和低4位互换并放回原位置的程序,找出错误并改正。DATASEGMENTDD1DB23HDATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXLEASI,OFFSETDD1MOVAL,[SI]MOVCL,4RCRAL,CLMOV[SI],ALMOVAH,4CHINT21HCODEENDSENDSTART【解答】程序第8行错误:LEASI,OFFSETDD1,应去掉OFFSET;程序第10行错误:RCRAL,CL,应使用ROR或ROL,改为RORAL,CL4.10编写程序,比较两个字符串STRING1和STRING2所含字符是否完全相同,若相同则显示MATCH,若不同则显示NOMATCH。答案:datareasegmentstring1db'asfioa'string2db'xcviyoaf'mess1db'MATCH','$'mess2db'NOMATCH','$'datareaendsprognamsegmentassumecs:prognam,ds:datareamainprocfarstart:pushdssubax,axpushaxmovax,datareamovds,axmoves,axbegin:movcx,string2-string1movbx,mess1-string2cmpbx,cxjnzdispnoleadx,addrleasi,string1leadi,string2repecmpsbjnedispnomovah,9leadx,mess1int21hretdispno:movah,9leadx,mess2int21hretmainendpprognamendsendstart4.11根据字节变量control中的各位被置位情况控制程序转移到8个远过程中的一个。【解答】DATASEGMENTSUBSTABLEDWSUBR1DWSUBR2DWSUBR3DWSUBR4DWSUBR5DWSUBR6DWSUBR7DWSUBR8CONTROLDB40HDATAENDSSS_SEGSEGMENTSTACKDB100DUP(0)SS_SEGENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:SS_SEGMAINPROCFARPUSHDSXORAX,AXPUSHAXMOVAX,DATAMOVDS,AXMOVBX,OFFSETSUBSTABLEMOVAL,CONTROLDIVERT:RCRAL,1JCGETAGADDBX,2JMPSHORTDIVERTGETAG:CALL[BX]RETMAINENDPSUBR1PROC…………RETSUBR1ENDP…………SUBR8PROC…………RETSUBR8ENDPCODEENDSENDMAIN4.12编写一个程序,接收从键盘输入的10个十进制数字,输入回车符则停止输入,然后将这些数字加密后(用XLAT指令变换)存入内存缓冲区BUFFER。加密表为;输入数字:0,1,2,3,4,5,6,7,8,9密码数字:7,5,9,1,3,6,8,0,2,4答案:Datasegmentscodedb7,5,9,1,3,6,8,0,2,4bufferdb10dup(?)DataendsCodesegmentassumecs:prognam,ds:datareastart:movax,Datamovds,axmovsi,0movcx,10leabx,scodeinput:movah,01int21hcmpal,0ahjzexitandal,0fhxlatmovbuffer[si],alincsiloopinputexit:movah,4chint21hCodeendsEndstart4.13从键盘输入一系列字符,以回车符结束,编程统计其中非数字字符的个数。【解答】DATASEGMENTBLOCKDB100DUP(?)COUNTDB?DATAENDSCODESEGMENTASSUMEDS:DATA,CS:CODESTART:MOVAX,DATAMOVDS,AXMOVDL,0LEASI,BLOCKLP:MOVAH,1INT21HCMPAL,0DHJZEXITMOV[SI],ALCMPAL,30HJAENEXTCMPAL,39HJBENEXTINCDLNEXT:INCSIJMPLPEXIT:MOVCOUNT,DLMOVAH,4CHINT21HCODEENDSENDSTART4.14请用16进制和10进制分别显示内存单元中一个字节的有符号数。【解答】DATASEGMENTDATA1DB088HDATA2DB4DUP(0)DATAENDSSTACKSEGMENTSTACKDB100DUP(?)STACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKMAINPROCFARPUSHDSXORAX,AXPUSHAXMOVAX,DATAMOVDS,AXHEXN:MOVAL,DATA1MOVCL,4SHRAL,CLCALLDISPL1MOVAL,DATA1ANDAL,0FHCALLDISPL1DECN:MOVAL,DATA1SHLAL,1JNCEEEMOVDL,'-'MOVAH,2INT21HMOVAL,DATA1NEGALJMPDECN0EEE:MOVAL,DATA1DECN0:LEABX,DATA2XORSI,SIMOVDL,10DECN1:XORAH,AHDIVDLMOV[BX+SI],AHINCSIANDAL,0FFHJZAAAJMPDECN1AAA:DECSIJZBBBMOVAL,BYTEPTR[BX+SI]CALLDISPL1JMPAAABBB:MOVAL,BYTEPTR[BX]CALLDISPL1RETMAINENDPDISPL1PROCPUSHAXADDAL,30HCMPAL,39HJNACCCADDAL,07HCCC:MOVDL,ALMOVAH,2INT21HPOPAXRETDISPL1ENDPCODEENDSENDMAIN4.15在数据段中以buffer单元开始连续存放10个8位二进制无符号数,将其中最大数找出来,存于max单元中,试编程。【解答】datasegmentbufferdb27,17,100,65,12,36,79,41,88,3maxdb?dataendsss_segsegmentstackdb100dup(0)ss_segendscodesegmentassumecs:code,ds:data,ss:ss_segmainprocfarmovax,datamovds,axmovcx,9movbx,0moval,buffer[bx]main1:addbx,2cmpal,buffer[bx]jgenextmoval,buffer[bx]next:loopmain1movmax,almovax,4c00hint21hmainendpcodeendsendmain4.16在数据段longdata中存放32位二进制无符号数(低位在前),将该变量以16进制形式显示输出,试编程。【解答】DATASEGMENTLONGDATADD0123ABC56HSTRINGDB'THENUBERIS:$'DATAENDSS

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

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

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

×
保存成功