您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 第7章输入输出和中断
(1)答:中断和子程序调用之间有相似之处,也有不同之处。它们的工作过程非常相似,即暂停当前程序的执行,转而执行另一个程序段,当该程序段执行完时,CPU都自动恢复源程序的执行。它们的主要差异有以下几个方面:1.子程序调用一定是程序员在编写源程序时事先安排好的,是可知的,而中断是由中断源根据自身的需要产生的,是不可预见的(用指令INT引起的中断除外)。2.子程序调用是用CALL指令来实现的,但中断是没有调用指令的,只有发出中断请求的事件(指令INT是发出内部中断信号,不要理解为调用中断服务程序)。3.子程序的返回指令是RET,而中断服务程序的返回指令是IRET/IRETD。4.在通常情况下,子程序是由应用系统的开发者编写的,而中断服务程序是由系统软件设计者编写的。(2)答:响应中断的过程是先保护现场和返回地址的,然后再进入中断响应程序的运行。现场包括通用寄存器和标志位寄存器的内容,而调用子程序一般有用户自己来保护特定的寄存器,通常不保护标志位寄存器。由于保护内容的不同,在返回时,从堆栈中弹出的内容也就不同。所以为了区别返回指令的功能,需要分别设置中断返回指令IRET指令和子程序返回RET指令。(3)程序如下:DISPLAYPROCUSESAXBX;子句USES在MASM6。X中有效,NEXT:MOVBX,DXMOVD1,BYTEPRT[BX]CMPD1,0JEFINISHMOVAH,2INT21HINCBXJMPNEXTFINISH:RETDISPIAYENDP(4)程序如下:CODE1SEGMENTCODEASSUMECS:CODE1DISPLAYPROCUSESAX;以十六进制的形式显示寄存器DL低4位二进制ANDDL,OFHCMPDL,9JBBELOW1ADDDL,7HBELOW1:ADDDL,30HMOVAH,2INT21HRETDISPLAYENDPDISPKEYPROCUSESAXCXDXMOVAH,0INT16H;从键盘读入字符CMPAL,0;如果为普通字符则子程序结束JNEOVERMOVDL,AHMOVCL,4SHRDL,CLCALLDISPLAY;按十六进制显示高4位二进制MOVDL,AHCALLDISPLAY;按十六进制显示低4位二进制OVER:RETDISPKEYENDPSTART:CALLDISPKEY;调用子程序MOVAX,4C00H;程序结束INT21HCODE1ENDSENDSTART(5)程序如下:DATA1SEGMENTNAME1DBZHANGSANDISPMODEDB?DATA1ENDSCODE1SEGMENTASSUMECS:CODE1,DS:DATA1START:MOVAX,DATA1;初始化数据段寄存器MOVDS,AXMOVAH,0FH;保存当前显示模式INT10HMOVDISPMODE,ALMOVAH,0MOVAL,3;设置为80×25彩色文本显示模式INT10HMOVAX,DSMOVES,AXMOVBP,OFFSETNAME1MOVDX,1849H;坐标(24,73)MOVCX,6MOVBH,0MOVBL,9AH;显示字符的颜色MOVAH,13HMOVAL,0INT10H;在屏幕右下角显示姓名MOVAH,0;等待键盘输入INT16HMOVAH,0;恢复原先的显示模式MOVAL,DISPMODEINT10HMOVAX,4C00H;程序结束INT21HCODE1ENDSENDSTART(6)程序如下:.MODELSMALL.CODE.STARTUPMOVAX,OB800HMOVDS,AXMOVCX,2000;屏幕上所有字母个数:25×80XORBX,BX;屏幕缓冲区中的第0个字节AGAIN:MOVAL,[BX].IF(AL='A')&&(AL='Z');MASMV6.X支持,其他可能不支持这种写;法,下同SUBAL,20H;小写字母变为大写字母.ELSEIF(AL='A')&&(AL='Z')ADDAL,20H;小写字母变为大写字母.ENDIFMOV[BX],AL;把变化后的字母保存到显示缓冲区中ANDBX,2;移到下一个显示字母LOOPAGAIN.EXITEND(7)程序如下:.MODELSMALL.CODE.STARTUPMOVAX,0B800HMOVDS,AXMOVCX,2000;屏幕上所有字符个数:25×80XORBX,BX;屏幕缓冲区中的第0个字节AGAIN:MOVAX,[BX];AL是显示字符,AH是字符的显示属性.IF(AL='0')&&(AL='9')MOVAH,34H;改变数字字符的属性.ENDIFMOV[BX],AX;把变化后的字符保存到显示缓冲区中ADDBX,2;移到下一个显示字符LOOPAGAIN.EXITEND(8)程序如下:CODE1SEGMENTASSUMECS:CODE1,DS:DATA1;GETCURRENTCURSORPOSITION;INPUT:NONE;OUTPUT:DH—LINENUMBER,DL—COLUMNNUMBERGETCURSORPOSITIONPROCUSESAXBXCXMOVAH,3MOVBH,0INT10HRETGETCURSORPOSITIONENDP;SETCURRENTCURSORPOSITION;INPUT:DH—LINENUMBER,DL—COLUMNNUMBER;OUTPUT:NONESETCURSORPOSITIONPROCUSESAXBXCXMOVAH,2MOVBH,0INT10HRETSETCURSORPOSITIONENDP;MOVECURSORTOTHEHEADOFLINE;INPUT:NONE;OUTPUT:NONEHOMEKEYPROCCALLGETCURSORPOSITIONMOVDL,0CALLSETCURSORPOSITIONRETHOMEKEYENDP;MOVECURSORTOTHEENDOFLINE;INPUT:NONE;OUTPUT:NONEENDKEYPROCCALLGETCURSORPOSITIONMOVDL,79CALLSETCURSORPOSITIONRETENDKEYENDP;BELLRING;INPUT:NONE;OUTPUT:NONERINGBELLPROCUSESAXBXCXMOVAH,2MOVDL,7INT21HRETRINGBELLENDP;MOVECURSORTONEXTLINE;INPUT:NONE;OUTPUT:NONEDOWNARROWKEYPROCCALLGETCURSORPOSITIONCMPDH,24JAEBELL1INCDHCALLSETCURSORPOSITIONRETBELL1:CALLRINGBELLRETDOWNARROWKEYENDP;MOVECURSORTOPREVIOUSLINE;INPUT:NONE;OUTPUT:NONEUPARROWKEYPROCCALLGETCURSORPOSITIONCMPDH,0JEBELL2DECDHCALLSETCURSORPOSITIONRETBELL2:CALLRINGBELLRETUPARROWKEYENDP;MOVECURSORTOLEFTPOSITION;INPUT:NONE;OUTPUT:NONELEFTARROWKEYPROCCALLGETCURSORPOSITIONCMPDL,0JEPREVIOUSLINEDECDLCALLSETCURSORPOSITIONRETPREVIOUSLINE:CMPDH,0JEBELL3DECDHMOVDL,79CALLSETCURSORPOSITIONRETBELL3:CALLRINGBELLRETLEFTARROWKEYENDP;MOVECURSORTORIGHTPOSITION;INPUT:NONE;OUTPUT:NONERIGHTARROWKEYPROCCALLGETCURSORPOSITIONCMPDL,79JAENEXTLINEINCDLCALLSETCURSORPOSITIONRETNEXTLINE:CMPDH,24JEBELL4INCDHMOVDL,0CALLSETCURSORPOSITIONRETBELL4:CALLRINGBELLRETRIGHTARROWKEYENDP;KEYASCIICHARACTERATTHEFIRSTLINEWITHTHESAMECOLUMNTOCURSOR;INPUT:AL—ASCIICHARACTER;OUTPUT:NONEWRITEKEYPROCUSESAXBXCXCALLGETCURSORPOSITIONPUSHDXMOVDH,0CALLSETCURSORPOSITIONMOVAH,0AHMOVBX,0MOVCX,1INT10HPOPDXCALLSETCURSORPOSITIONRETWRITEKEYENDPSTART:MOVAX,DATA1MOVDS,AXNEXTKEY:MOVAH,0;WAITFORANYKEYBEPRESSEDINT16HCMPAX,11BH;CHECKESCJEFINSHCMPAX,4700HJNENEXT1CALLHOMEKEYJMPNEXTKEYNEXT1:CMPAX,4F00HJNENEXT2CALLENDKEYJMPNEXTKEYNEXT2:CMPAX,5000HJNENEXT3CALLDOWNARROWKEYJMPNEXTKEYNEXT3:CMPAX,4B00HJNENEXT4CALLLEFTARROWKEYJMPNEXTKEYNEXT4:CMPAX,4D00HJNENEXT5CALLRIGHTARROWKEYJMPNEXTKEYNEXT5:CMPAX,4800HJNENEXT6CALLUPARROWKEYJMPNEXTKEYNEXT6:.IF(AL='0')&&(AL='9')||(AL='A')&&(AL='Z')||(AL='A')&&(AL='Z')CALLWRITEKEYJMPNEXTKEY.ENDIFJMPNEXTKEYFINSH:MOVAX,4C00HINT21HCODE1ENDS(9)程序如下:①DATA1SEGMENTDISPMODEDB?DATA1ENDSCODE1SEGMENTASSUMECS:CODE1,DS:DATA1START:MOVAX,DATA1MOVDS,AXMOVAH,0FH;SAVECURRENTDISPLAYMODEINT10HMOVDISPMODE,ALMOVAH,0MOVAL,12HINT10HMOVDX,0NEXT:MOVAH,0CHMOVAL,9;BRIGHTBLUEMOVCX,320INT10HINCDXCMPDX,480JBNEXTMOVAH,0;WAITFORANYKEYBEPRESSEDINT16HMOVAH,0;RESTOREDISPLAYMODEMOVAL,DISPMODEINT10HMOVAX,4C00HINT21HCODE1ENDSENDSTART②DATA1SEGMENTDISPMODEDB?DATA1ENDSCODE1SEGMENTASSUMECS:CODE1,DS:DATA1START:MOVAX,DATA1MOVDS,AXMOVAH,0FH;SAVECURRENTDISPLAYMODEINT10HMOVDISPMODE,ALMOVAH,0MOVAL,12HINT10HMOVDX,478NEXT1:MOVCX,0NEXT:MOVAH,0CHMOVAL,2;GREENINT10HINCCXCMPCX,640JBNEXTINCDXCMPDX,480JBNEXT1MOVAH,0;WAITFORANYKEYBEPRESSEDINT16HMOVAH,0;RESTOREDISPLAYMODEMOVAL,DISPMODEINT10HMOVAX,4C00HINT21HCODE1ENDSENDSTART③DATA1SEGMENTDISPMODEDB?DATA1ENDSCODE1SEGMENTA
本文标题:第7章输入输出和中断
链接地址:https://www.777doc.com/doc-2198684 .html