1.从屏幕上输入小写字母,转化为大写字母输出(解法1)DATA SEGMENTMESSAGE DB "ENTER A STRING:",0AH,0DH,'$' MAXLENGTH DB 50,?,50 DUP(?) ;每次最多可以输入49个字符DATA ENDSCODE SEGMENTASSUME DS:DATA,CS:CODESTART:MOV AX,DATAMOV DS,AXLEA DX,MESSAGE ;输出ENTER A STRINGMOV AH,09HINT 21HLEA DX,MAXLENGTH ;输入字符串MOV AH,0AH ;键盘输入到缓冲区,DS:DX=缓冲区首址INT 21H ;(DS:DX)=缓冲区最大字符数,(DS:DX+1)=实际输入的字符数MOV AH,02H ;输出回车换行MOV DL,0AHINT 21HMOV AH,02HMOV DL,0DHINT 21HMOV CL,MAXLENGTH+1;把字符的实际长度放入寄存器CLMOV CH,0MOV BH,02HLEA SI,MAXLENGTH+2;取字符串的基地址放入SIXUN:MOV AL,[SI]CMP AL,'Z'JBE S1 ;小于等于'Z'转移JMP S3S1:CMP AL,'A'JAE DA ;大于等于'A'转移JMP OUTPUTDA:ADD AL,20HJMP OUTPUTS3:CMP AL,'z' ;小于等于小Z转移JBE S4S4:CMP AL,'a' ;大于等于小a转移JAE XIAOJMP OUTPUTXIAO:SUB AL,32JMP OUTPUTOUTPUT:MOV DL,ALMOV AH,02H ;显示输出INT 21HINC SILOOP XUNMOV AH,4CHINT 21HCODE ENDSEND START(解法2);将输入的小写字母转化为大写字母输出,输入回车结束CODE SEGMENTASSUME CS:CODEBEGIN:MOV AH,01HINT 21HCMP AL,0DH ;ASCII OF CARRIAGE RETURNJE EXITCMP AL,61H ;ASCII OF 'a'JB STOPCMP AL,7AH ;ASCII OF 'z'JA STOPSUB AL,20HSTOP:MOV DL,ALMOV AH,2INT 21HJMP BEGINEXIT:MOV AH,4CHINT 21HRETCODE ENDSEND BEGIN2.输入一个字符,找出它的前导字符和后续字符,并按顺序显示这三个字符.(解法1)CODE SEGMENTMAIN PROC FARASSUME CS:CODESTART:PUSH DSXOR AX,AXPUSH AXMOV AH,01HINT 21HCMP AL,61HJB EXITCMP AL,7AHJA EXITMOV CL,ALDEC ALMOV DL,ALMOV AH,02HINT 21HMOV DL,CLMOV AH,02HINT 21HAND AL,01HINC CLMOV DL,CLMOV AH,02HINT 21HEXIT:MOV AX,4C00HINT 21HRETMAIN ENDPCODE ENDSEND START(解法2).MODEL SMALL.STACK 200H.DATAimsg db 'Input:$' ;输入提示信息omsg db 0Dh,0Ah,'Output:$' ;输出提示信息string db 3 dup(0),'$' ;存放三个字符.CODESTART:mov ax,@datamov ds,axlea dx,imsgmov ah,9int 21hmov ah,1int 21hlea di,stringdec almov cx,3s:mov [di],alinc diinc alloop slea dx,omsgmov ah,9int 21hlea dx,stringmov ah,9int 21hMOV AH,07HINT 21HMOV AX,4C00HINT 21HEND START3.将AX寄存器中的16位数分成4组,每组4位,然后把这四组数分别放在AL,BL,CL,DL中.MODEL SMALL,C.CODE.STARTUPMOV AX,3456HMOV BX,AXMOV CL,4ROL AX,CLMOV BX,AXAND AL,0FH ;AL中是15,14,13,12ROL BX,CLMOV DX,BXAND BL,0FH ;BL中是11,10,9,8AND AH,0FHMOV CH,AH ;CH中是7,6,5,4MOV CL,CHAND DH,0FH ;DH中是3,2,1,0MOV DL,DH.EXIT 0END4.试编写一程序,要求比较两个字符串STRING1和STRING2所含字符是否相同,若相同则显示'MATCH',若不相同则显示'NOT MATCH'..MODEL SMALL.DATASTRING1 DB "LDSKFJSLDKF"LENG1 EQU $-STRING1STRING2 DB "LDSKFJSLDKP"LENG2 EQU $-STRING2MSG1 DB "MATCH",24HMSG2 DB "NOT MATCH",24H.CODEMOV AX,@DATAMOV DS,AXMOV ES,AXMOV BX,LENG1MOV CX,LENG2CMP BX,CXJNZ NOT_MATCHLEA SI,STRING1LEA DI,STRING2CLDREPZ CMPSBJZ _MATCHNOT_MATCH:LEA DX,MSG2MOV AH,09HINT 21HJMP _EXIT_MATCH:LEA DX,MSG1MOV AH,09HINT 21H_EXIT:MOV AH,07HINT 21HMOV AX,4C00HINT 21HEND5.要求能从键盘接收一个个位数,然后响铃N次(响铃的ASCII码为07) .MODEL SMALL.DATAMSG DB "YOUR INPUT IS NOT 1-9!",24H .CODE.STARTUPMOV AH,0INT 16H ;接收一个键盘输入CMP AL,31HJB ERRORCMP AL,39HJA ERRORMOV CL,ALSUB CL,30HCYCLE:MOV DL,7MOV AH,09HINT 21HMOV AH,07H ;按一下键就响一下铃声INT 21HLOOP CYCLEJMP _EXITERROR:LEA DX,MSGMOV AH,09HINT 21HMOV AH,07HINT 21H_EXIT:.EXIT 0END6.编写程序,将一个包含有20个数据的数组M分成两个数组,正数数组P 和负数数组N,并分别把这两个数组中数据的个数显示出来..MODEL SMALL,C.DATAINDEX DB 12,-20,4,05H,11H,2AH,-11,2,3,09HDB -3,0,-9,44H,32H,33H,34H,-5,40H,22HP DB 0,20 DUP(0) ;存放正数N DB 0,20 DUP(0) ;存放负数.CODEDISPLAY PROC NEAR USES AXAND AH,0FH.IF AH>= 0AH && AH<= 0FHADD AH,07H.ENDIFADD AH,30HMOV DL,AHMOV AH,02HINT 21HMOV AH,07HINT 21HRETDISPLAY ENDP.STARTUPLEA DI,P+1LEA SI,N+1LEA BX,INDEXMOV CX,14HCYCLE:CMP BYTE PTR [BX],0JG NOSIGNINC AL ;AL中存放负数MOV DL,BYTE PTR [BX]MOV BYTE PTR DS:[DI],DLINC DIINC BXLOOP CYCLENOSIGN:INC AH ;AH中存放正数MOV DL,BYTE PTR [BX]MOV BYTE PTR DS:[SI],DLINC SIINC BXLOOP CYCLEMOV P,AHMOV N,ALCALL DISPLAYMOV AH,ALCALL DISPLAY.EXIT 0END7.试编制一个汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它存放在AX中.datarea segmentdata dw 10,2,4,8,7,7,69,65,55,89,95dw 25,39,77,88,25,1,47,88,8,8,77,88,22 count=($-data)/2num dw 0ffeehdatarea endscode segmentmain proc farassume cs:code,ds:datareapush dsmov ax,0push axbegin:mov ax,datareamov ds,axmov bl,2mov cx,countlea si,dataA:mov ax,[si]mov dx,axdiv blcmp ah,0jne circlecmp dx,numjb Bcircle:add si,2lopa:loop Aexit:mov ax,numretB:mov num,dxjmp lopamain endpcode endsend8.把AX中存放的16位二进制数K看作是8个二进制的"四分之一字节".试编写一程序,要求数一下值为3(即11B)的四分之一字节数,并将该数在终端上显示出来.MOV CX,8MOV DL,0NEXT3:ROR AX,1JNC NEXT1ROR AX,1JNC NEXT2INC DLNEXT2:LOOP NEXT3ADD DL, 30HMOV AH, 2INT 21HMOV AH, 4CHINT 21HNEXT1:ROR AX, 1JMP NEXT29.试编写一汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它存放在AX中..MODEL SMALL,C.DATA_DATA DW 100 DUP(?).CODE.STARTUPLEA SI,_DATAMOV AX,[SI]MOV CX,100CYCLE:ADD SI,2.IF AX< [SI]MOV AX,[SI].ENDIFLOOP CYCLE.EXIT 010.设有一段英文,其字符变量名为ENG,并以$字符结束,试编写一程序,查对单词SUN在该文中的出现次数,并以格式"SUN****"显示出次数..MODEL SMALL.386.DATAENG DB 'SUN','SUN JAVA',24HMESSAGE DB 'SUN:','$' .STACK 100H.CODEMAIN PROC FAR START:PUSH DSAND AX,0PUSH AXMOV AX,@DATAMOV DS,AXMOV AX,0HMOV SI,1HSUBSI1:SUB SI,1HSUBSI2:SUB SI,1H COMPARES:ADD SI,1HMOV DL,ENG[SI]CMP DL,24HJE PRINTCMP DL,53HJNE COMPARES COMPAREU:ADD SI,1HMOV DL,ENG[SI]CMP DL,55HJNE SUBSI2 COMPAREN:ADD SI,1HMOV DL,ENG[SI]CMP DL,4EHJNE SUBSI1INC AXJMP COMPARESPRINT:LEA DX,MESSAGEPUSH AXMOV AH,09HINT 21HPOP AXCALL SHOWNUMBER EXIT:RETMAIN ENDP SHOWNUMBER PROC NEAR COVERNUM:DAAMOV DX,AXMOV CL,4HSHOW:ROL DX,4HPUSH DXAND DX,0FHADD DX,30HMOV AH,02HINT 21HPOP DXLOOP SHOWRETSHOWNUMBER ENDPEND START11.从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示出计数结果..MODEL SMALL.386.CODEMAIN PROC FARSTART:PUSH DSMOV AX,0PUSH AXMOV CX,0INPUT:MOV AH,1HINT 21HCOMPARE:CMP AL,24HJE PRINTCMP AL,30HJL ADDCOUNTCMP AL,39HJG ADDCOUNTADDCOUNT:ADD AX,1HJMP INPUTCALL SHOWNUMBEREXIT: RETMAIN ENDPSHOWNUMBER PROC NEARCOVERNUM:DAAMOV DX,AXMOV CL,2HSHOW:ROL DL,4HPUSH DXAND DL,0FHADD DL,30HMOV AH,02HINT 21HPOP DXLOOP SHOWRETSHOWNUMBER ENDPEND START12.有一个首地址为MEM的100D字数组,试编制程序删除数组中所有为零的项,并将后续项向前压缩,最后将数组的剩余部分补上零..model small.386.stack 100Hmem dw12,0,0,0,0,0,1,2,3,6,4,7,8,2,1,0,0,54,5,0,2,4,7,8,0,5,6,2,1,4,8,5,1,45,7 ,5,1,2,0,2,4,0,2,54,0,12,0,0,0,0,0,1,2,3,6,4,7,8,2,1,0,0,54,5,0,2,4,7,8,0,5,6,2,1,4,8,5,1,45,7,5,1, 2,0,2,4,0,2,54,0,45,7,5,1,2,0,2,4,0,2.codeMAIN PROC FARstart:push dsand ax,0push axmov ax,@datamov ds,axmov ax,0Hmov bx,64Hmov cx,64Hmov si,0FFFEHrepeat:ADD si,2Hcmp MEM[si],0HJE callsloop repeatcalls:INC axcall sortcmp ax,1HJE lastValueDEC cxjmp repeatexit :retlastValue:mov mem[bx],0HDEC cxjmp repeatMAIN ENDPsort PROC NEARpush cxpush sisub si,2Hs:add si,2Hmov dx,mem[si]mov mem[si+2],dxloop sreturn:pop sipop cxretsort ENDPEND start13.在STRING到STRING+99单元中存放着一个字符串,试编制一程序测试该字符串中是否存在数字.如有,则把CL的第5位置1,否则将该位置0. DSEG SEGMENTA DW ?B DW ?DSEG ENDSCSEG SEGMENTMAIN PROC FARASSUME CS:CSEG,DS:DSEG START:PUSH DSSUB AX, AXPUSH AXMOV AX, DSEGMOV DS, AXBEGIN:MOV AX, AMOV AX, BXOR AX, BXTEST AX, 0001JZ EXITXCHG BX, AMOV B, BXJMP EXITCLASS:TEST BX, 0001JZ EXITINC BINC AEXIT:RETMAIN ENDPCSEG ENDSEND START14.在首地址为TABLE的数组中按递增次序存放着100H个16位补码数,试编写一个程序把出现次数最多的数及其出现次数分别存放在AX和CX中.DATA SEGMENTTABLE DW 100H DUP (?)MDATA DW ? ; 存放出现次数最多的数COUNT DW 0 ; 存放出现次数DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMOV BX, 100HMOV DI, 0 ; DI为数组TABLE的指针NEXT:MOV DX, 0MOV SI, 0MOV AX, TABLE[DI]MOV CX, 100HCOMP:CMP TABLE[SI], AXJNE _ADDRINC DX_ADDR:ADD SI, 2LOOP COMPCMP DX, COUNTJLE CHANGMOV COUNT, DXMOV MDATA, AXCHANG:ADD DI, 2DEC BXJNZ NEXTMOV CX, COUNTMOV AX, MDATAMOV AX,4C00HINT 21HCODE ENDSEND START15.数据段中已定义了一个有n个字数据的数组M,试编写一程序求出M 中绝对值最大的数,把它放在数据段的M+2n单元中,并将该数的偏移地址存放在M+2(n+1)单元中.DSEG SEGMENTX DW -4FX DW ?DSEG ENDSCSEG SEGMENTMAIN PROC FARASSUME CS:CSEG,DS:DSEGSTART:PUSH DSPUSH AXMOV AX, DSEGMOV DS, AXBEGIN:CMP X, 5JG A0CMP X, -5JL A0MOV BX,1SUB BX, XMOV FX, BXRETA0:MOV FX, 0RETMAIN ENDPCSEG ENDSEND START16.在首地址为DATA的字数组中,存放了100H个16位补码数,试编写一程序,求出它们的平均值放在AX寄存器中;并求出数组中有多少个数小于此平均值,将结果放在BX寄存器中..MODEL SMALL.STACK 200H.DATADA_TA DW 100H DUP(?).CODE.STARTUPXOR BX,BXXOR DX,DXMOV CX,100HLEA SI,DA_TACYCLE:ADD AX,[SI]ADC DX,0INC SIINC SIDEC CXCMP CX,0JNZ CYCLEMOV CX,100HDIV CX ;计算平均值,存放在AX中.LEA SI,DA_TACOMPARE:CMP AX,[SI]JA NEXT ;计算小于AX的值,其个数存放在BX中INC BXNEXT:INC SIINC SIDEC CXCMP CX,0JNZ COMPARE.EXIT 0END17.试编制一个程序,把AX中的16进制数转化为ASCII码,并将对应的ASCII码依次存放到MEM数组中的四个字节中.例如:当(AX)=2A49H时,程序执行完后,MEM中的4个字节内容为39H,34H,41H,32H.;MODE=DOSDATA SEGMENTSOURCE DW 2A49HMEM DB 4 DUP(?)DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATAMOV DS,AXMOV DX,SOURCELEA BX,MEMMOV CX,4LB:MOV AX,DXAND AX,000FHCMP AL,10JC ADADD AL,7AD:ADD AL,30HMOV [BX],ALINC BXSHR DX,1SHR DX,1SHR DX,1SHR DX,1LOOP LBMOV AH,4CHINT 21HCODE ENDSEND START18.把0-100D之间的30个数存入以GRADE为首地址的30个字数组中,GRADE+i表示学号为i+1的学生成绩.另一个数组RANK为30个学生的名次表,其中RANK+i的内容是学号为i+1的学生的名次.编写一程序,根据GRADE中的学生成绩,将学生名次填入RANK数组中.(提示:一个学生的名次等于成绩高于这个学生的人数加1)DSEG SEGMENTGRADE DW 30 DUP(?)RANK DW 30 DUP(0)DSEG ENDSCSEG SEGMENTMAIN PROC FARASSUME CS:CSEG,DS:DSEGSTART: PUSH DSSUB AX,AXPUSH AXMOV AX,DSEGMOV DS,AXBEGIN:MOV DI,0MOV CX,30LOOP1:PUSH CXMOV CX,30MOV SI,0MOV AX,GRADE[DI]MOV DX,0LOOP2:CMP GRAD[SI],AXJBE GOONINC DXGOON :ADD SI,2LOOP LOOP2POP CXINC DXMOV RANK[DI],DXADD DI,2LOOP LOOP1RETMAIN ENDPCSEG ENDSEND START19.已知数组A包含15个互不相等的整数,数组B包含20个互不相等的整数.试编制一程序,把既在A中又在B中出现的整数存放于数组C中。