第6章习题及答案

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

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

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

资源描述

第6章8086/8088汇编语言程序设计习题1.下列语句在存储器中分别为变量分配多少字节空间?并画出存储空间的分配图。VAR1DB10,2VAR2DW5DUP(?),0VAR3DB‘HOWAREYOU?’,‘$’VAR4DD-1,1,0解:VAR1DB10,2;2个字节VAR2DW5DUP(?),0;12个字节VAR3DB‘HOWAREYOU?’,‘$’;13个字节VAR4DD-1,1,0;12个字节存储空间的分配图略去2.已知内存DATA单元存放一个字数据,统计其含有0的个数,并送入RESULT单元。解:DATSEGMENT;数据段DATADW0F7F7HRESULTDB?DATENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACKMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVCX,16MOVBL,0MOVAX,DATAAGAIN:SHLAX,1JCNEXTINCBLNEXT:LOOPAGAINMOVRESULT,BLRETMAINENDPCODEENDSENDSTART3.试编程序将内存从40000H到4BFFFH的每个单元中均写入55H,并再逐个单元读出比较,看写入的与读出的是否一致。若全对,则将AL置7EH;只要有错,则将AL置81H。解:DATSEGMENTAT4000H;数据段DATADB49152DUP(?)DATENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACK,ES:DATMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVES,AXMOVDI,0MOVCX,49152MOVAL,55HCLDREPSTOSB;写入MOVCX,49152MOVSI,0AGAIN:LODSB;读出CMPAL,55HJNZERR1LOOPAGAINMOVAL,7EHJMPEXTERR1:MOVAL,81HEXT:NOPRETMAINENDPCODEENDSENDSTART4.已知从数据段DATA单元开始存放字节型的带符号数X和Y,请设计计算Y=6X+8的程序。解:DATSEGMENT;数据段DATADB-2SUMDB?DATENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACKMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVAL,DATA;XALSHLAL,1;计算2XALMOVBL,AL;保护2XBLSHLAL,1;计算4XALADDAL,BL;计算6XADDAL,8;计算6X+8MOVSUM,ALRETMAINENDPCODEENDSENDSTART5.已知从数据段BUF单元开始存放15个字节型数据,请设计程序将其中负数和零分别送往MINUS和ZERO开始的存储器单元。解:DATSEGMENT;数据段BUFDB17H,23H,0F8H,0,4FH,73H,4EH,0FBHDB0,0F0H,9EH,51H,82H,9CH,0MINUSDB15DUP(?)ZERODB15DUP(?)DATENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACKMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVCX,15MOVDI,OFFSETBUFMOVSI,OFFSETMINUSMOVBX,OFFSETZERONEXT1:MOVAL,[DI]TESTAL,80HJNZMICMPAL,0JZZOJMPNEXT2ZO:MOV[BX],ALINCBXJMPNEXT2MI:MOV[SI],ALINCSINEXT2:INCDILOOPNEXT1RETMAINENDPCODEENDSENDSTART6.在当前数据段4000H开始的128个单元中存放一组数据,试编程序将它们顺序搬移到A000H开始的顺序128个单元中,并将两个数据块逐个单元进行此较;若有错将BL置00H;全对则将BL置FFH,试编程序。解:DATSEGMENT;数据段ORG4000HBUF1DB128DUP(5FH)DATENDSEXTRASEGMENT;附加段ORG0A000HBUF2DB128DUP(?)EXTRAENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACK,ES:EXTRAMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVAX,EXTRA;送附加段段地址MOVES,AXMOVCX,128;搬移数据块CLDMOVSI,OFFSETBUF1MOVDI,OFFSETBUF2REPMOVSBMOVCX,128;比较CLDMOVSI,OFFSETBUF1MOVDI,OFFSETBUF2REPECMPSBJNEERRORMOVBL,0FFHJMPEXTERROR:MOVBL,0EXT:NOPRETMAINENDPCODEENDSENDSTARTGIVEANEXAMPLE!7.试编程序,统计由40000H开始的16K个单元中所存放的字符“A“的个数,并将结果存放在DX中。解:DATSEGMENTAT4000H;数据段BUFDB1024DUP(‘GIVEANEXAMPLE!’)DATENDSSTACKSEGMENTSTDB100DUP(?)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DAT,SS:STACK,ES:DATMAINPROCFARSTART:MOVAX,STACK;送堆栈段段地址MOVSS,AXPUSHDS;返回DOS用MOVAX,0PUSHAXMOVAX,DAT;送数据段段地址MOVDS,AXMOVES,AXMOVDX,0;存放A个数MOVCX,16384LEADI,BUFMOVAL,‘A’CLDNEXT2:SCASBJNZNEXT1INCDXNEXT1:NOPLOOPNEXT2RETMAINENDPCODEENDSENDSTART

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

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

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

×
保存成功