資源描述:
《最新編寫(xiě)程序.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、3.22試編寫(xiě)一程序求出雙字長(zhǎng)數(shù)的絕對(duì)值。雙字長(zhǎng)數(shù)在A和A+2單元中,結(jié)果存放在B和B+2單元中。答:程序段如下:MOVAX,AMOVDX,A+2CMPDX,0JNSZHENSHU;不是負(fù)數(shù)則轉(zhuǎn)走NEGDXNEGAXSBBDX,0ZHENSHU:MOVB,AXMOVB+2,DXINT20H3.30編寫(xiě)程序段,把字符串STRING中的‘&’字符用空格符代替。STRINGDB‘ThedateisFEB&03’答:程序段如下:MOVCX,18MOVAL,‘&’CLDMOVDI,SEGSTRINGMOVES,DI;ES段基地址LEADI,STRINGREPNES
2、CASB;不相等重復(fù)JNENEXT;相等跳轉(zhuǎn)DECDIMOVES:BYTEPTR[DI],‘’;送空格符NEXT:┇3.31假設(shè)數(shù)據(jù)段中數(shù)據(jù)定義如下:STUDENT_NAMEDB30DUP(?)STUDENT_ADDRDB9DUP(?)PRINT_LINEDB132DUP(?)分別編寫(xiě)下列程序段:(1)用空格符清除PRINT_LINE域。(2)在STUDENT_ADDR中查找第一個(gè)‘-’。(3)在STUDENT_ADDR中查找最后一個(gè)‘-’。(4)如果STUDENT_NAME域中全是空格符時(shí),填入‘*’。(5)把STUDENT_NAME移到PRINT_L
3、INE的前30個(gè)字節(jié)中,把STUDENT_ADDR移到PRINT_LINE的后9個(gè)字節(jié)中。答:公共的程序段如下:MOVDI,DSMOVES,DI(1)MOVCX,132MOVAL.,‘’;空格的ASCII碼送AL寄存器CLDLEADI,PRINT_LINEREPSTOSB(2)MOVCX,9MOVAL.,‘-’CLDLEADI,STUDENT_ADDRREPNESCASBJNENO_DASHDECDINO_DASH:┇(3)MOVCX,9MOVAL.,‘-’STDLEADI,STUDENT_ADDRADDDI,9-1REPNESCASBJNENO_DAS
4、HINCDINO_DASH:┇(4)MOVCX,30MOVAL,‘’;空格的ASCII碼送AL寄存器CLDLEADI,STUDENT_NAMEREPESCASBJNENEXTMOVCX,30MOVAL,‘*’;“*”的ASCII碼送AL寄存器LEADI,STUDENT_NAMEREPSTOSBNEXT:┇(5)MOVCX,30CLDLEASI,STUDENT_NAMELEADI,PRINT_LINEREPMOVSBMOVCX,9STDLEASI,STUDENT_ADDR+9-1LEADI,PRINT_LINE+132-1REPMOVSB3.32編寫(xiě)一程序
5、段:比較兩個(gè)5字節(jié)的字符串OLDS和NEWS,如果OLDS字符串不同于NEWS字符串則執(zhí)行NEW_LESS;否則順序執(zhí)行程序。答:程序段如下:MOVCX,5CLDMOVDI,SEGOLDSMOVDS,DIMOVES,DILEASI,OLDSLEADI,NEWSREPECMPSBJNENEW_LESS┇NEW_LESS:┇3.47請(qǐng)編寫(xiě)一程序段,要求把ECX、EDX和ESI的內(nèi)容相加,其和存入EDI寄存器中(不考慮溢出)。答:MOVEDI,0也可為:MOVEDI,ECXADDEDI,ECXADDEDI,EDXADDEDI,EDXADDEDI,ESIADDE
6、DI,ESI3.49試編寫(xiě)一程序段,要求把BL中的數(shù)除以CL中的數(shù),并把其商乘以2,最后的結(jié)果存入DX寄存器中。答:MOVAL,BLMOVAH,0;假定為無(wú)符號(hào)數(shù),否則用CBW指令即可DIVCLMOVAH,0SHLAX,1;邏輯左移1位MOVDX,AX原(BP)低字節(jié)原(BP)高字節(jié)存儲(chǔ)器002EH002FH0030H0031H0032H0033H0034H0035H0036H0037H0038H0039H003AH003BH003CH003DH003EH003FH0040H堆棧幀原(SP)新(BP)新(SP)3.52題的答案3.51試編寫(xiě)一程序段,要求
7、在長(zhǎng)度為100H字節(jié)的數(shù)組中,找出大于42H的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入字節(jié)單元UP中;找出小于42H的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入字節(jié)單元DOWN中。答:JMPBEGIN;無(wú)條件轉(zhuǎn)移UPDB0DOWNDB0TABLEDB100HDUP(?);數(shù)組BEGIN:MOVCX,100HMOVBX,-1;數(shù)組下標(biāo)MOVSI,0MOVDI,0L1:INCBXCMPTABLE[BX],42HJAL2;高于JBL3;低于JMPL4;否則跳到L4L2:INCSI;UPJMPL4L3:INCDI;DOWNL4:LOOPL1MOVUP,SIMOVDOWN,DI4.11試寫(xiě)出一個(gè)完整的數(shù)據(jù)
8、段DATA_SEG,它把整數(shù)5賦予一個(gè)字節(jié),并把整數(shù)-1,0,2,5和4放在10