一、1.请任意输入一个字符串,将该串倒序后在屏幕上显示。
DATAS SEGMENTBUF DB 40DB ?DB 40 DUP(0)ACC DB 0CHAR DB ?DATAS ENDSSTACKS SEGMENTDB 100 DUP(0)STACKS ENDSCODES SEGMENTASSUME CS:CODES,DS:DATAS,SS:STACKS START:MOV AX,DATASMOV DS,AXMOV AH,0AHLEA DX,BUFINT 21H ; 输入字符串MOV AH,0EHMOV AL,0DHINT 10HMOV AL,0AHINT 10H ;回车换行LEA SI,BUFMOV AL,[SI+1]MOV AH,0MOV ACC,ALINC SIADD SI,AXL1: MOV DL,[SI]MOV AH,02HINT 21HDEC SIDEC ACCCMP ACC,0JNZ L1MOV AH,4CHINT 21HCODES ENDSEND START2.请任意输入一个字符串,统计其中空格和A的个数,并将结果显示在屏幕上。
DATA SEGMENTBUF DB 100DB ?DB 100 DUP(?) CHAR DB 0ACC DB 0SPACE DB 0CHARA DB 0 DATA ENDS STACK SEGMENT DB 100 DUP(0) STACK ENDS CODE SEGMENT ASSUMEDS:DATA,CS:CODE MAIN PROC FARMOV AX,DA TAMOV DS,AXLEA DX,BUFMOV AH,0AHINT 21H ;输入字符串MOV AH,02HMOV DL,0DHINT 21HMOV DL,0AHINT 21HLEA SI,BUFMOV AL,[SI+1]MOV ACC,ALMOV SI,2L: CMP BUF[SI],' 'JZ LSPACECMP BUF[SI],'A'JZ LCHARAINC SIDEC ACCCMP ACC,0JZ SHOWJMP LLSPACE:INC SPACEINC SIDEC ACCCMP ACC,0JZ SHOWJMP LLCHARA:INC CHARAINC SIDEC ACCCMP ACC,0JZ SHOWJMP LSHOW:CMP SPACE,0AHJAE SHOWSADD SPACE,30HMOV DL,SPACEMOV AH,2INT 21H ;若SPACE小于10个,直接输出个数SHOW1:MOV AH,0EHMOV AL,0DHINT 10HMOV AL,0AHINT 10HCMP CHARA,0AHJAE SHOWAADD CHARA,30HMOV AH,2MOV DL,CHARAINT 21H ;若A个数小于10,直接输出个数JMP EXITSHOWS:MOV AL,SPACEMOV AH,0MOV DL,10DIV DLADD AH,30HMOV SPACE,AHADD AL,30HMOV AH,2MOV DL,ALINT 21HMOV DL,SPACEINT 21HJMP SHOW1SHOWA:MOV AL,CHARAMOV AH,0MOV DL,10DIV DLADD AH,30HMOV CHARA,AHADD AL,30HMOV AH,2MOV DL,ALINT 21HMOV DL,CHARAINT 21HEXIT:MOV AH,4CHINT 21HMAIN ENDPCODE ENDSEND MAIN3.请任意输入一个字符串,将其中的空格全部删除,并将结果显示在屏幕上。
DATA SEGMENTBUF DB 100DB ?DB 100 DUP(?)INP DB 'Please input a string:','$'CHAR DB 0ACC DB 0DATA ENDSSTACK SEGMENTDB 100 DUP(0)STACK ENDSCODE SEGMENTASSUMEDS:DATA,CS:CODE,ES:ST ACKSTART: MOV AX,DA TAMOV DS,AX ; 赋初值MOV AH,09HLEA DX,INPINT 21H ; 提示输入MOV AH,0AHLEA DX,BUFINT 21H ; 输入字符串MOV AH,2MOV DL,0DHINT 21HMOV DL,0AHINT 21H ; 回车换行LEA SI,BUFMOV DL,[SI+1]MOV ACC,DLMOV SI,2LOP:MOV DL,BUF[SI]MOV CHAR,DLCMP CHAR,' 'JZ LADDMOV AH,2MOV DL,CHARINT 21H ;若不是空格则输出LADD:INC SIDEC ACCCMP ACC,0JZ EXITJMP LOP EXIT: MOV AH,4CHINT 21HCODE ENDSEND START4.请任意输入一个字符串,将其中A换成B,并将结果显示在屏幕上。
DATA SEGMENTINP DB 'Please input a string:','$'CHAR DB 0ACC DB 0BUF DB 50DB ?DB 50 DUP(0)DATA ENDSSTACK SEGMENTDB 100 DUP(0)STACK ENDSCODE SEGMENTASSUMECS:CODE,DS:DA TA START:MOV AX,DA TAMOV DS,AXMOV AH,9LEA DX,INPINT 21H ;提示输入字符串MOV AH,0AHLEA DX,BUFINT 21HMOV AH,2MOV DL,0DHINT 21HMOV DL,0AHINT 21H ;输入字符串LEA SI,BUFMOV DL,[SI+1]MOV ACC,DL ;记录字符串个数MOV SI,2MOV AH,2LA: MOV DL,BUF[SI]CMP DL,'A'JZ PUTCCINT 21HLAD:INC SIDEC ACCMOV DH,ACCCMP DH,0JZ EXITJMP LAPUTCC:MOV DL,'C'INT 21HINT 21HJMP LADEXIT:MOV AH,4CHINT 21HCODE ENDSEND START5.请任意输入一个字符串,将其中A换成CC,并将结果显示在屏幕上。
DATA SEGMENTINP DB 'Please input a string:','$'CHAR DB 0ACC DB 0BUF DB 50DB ?DB 50 DUP(0)DATA ENDSSTACK SEGMENTASSUMECS:CODE,DS:DA TA START:MOV AX,DA TAMOV DS,AXMOV AH,9LEA DX,INPINT 21H ;提示输入字符串MOV AH,0AHLEA DX,BUFINT 21HMOV AH,2MOV DL,0DHINT 21HMOV DL,0AHINT 21H ;输入字符串LEA SI,BUFMOV DL,[SI+1]MOV ACC,DL ;记录字符串个数MOV SI,2MOV AH,2LA: MOV DL,BUF[SI]CMP DL,'A'JZ PUTCCINT 21HLAD:INC SIDEC ACCMOV DH,ACCCMP DH,0JZ EXITJMP LAPUTCC:INT 21HINT 21HJMP LAD EXIT:MOV AH,4CHINT 21H CODE ENDS END START6.请任意输入一个字符串,将其中大写字母换成小写字母,并将结果显示在屏幕上。
DATA SEGMENTINP DB 'Please input a string:','$'CHAR DB 0ACC DB 0BUF DB 50DB ?DB 50 DUP(0)DATA ENDSSTACK SEGMENTDB 100 DUP(0)STACK ENDSCODE SEGMENTASSUMECS:CODE,DS:DA TA START:MOV AX,DA TAMOV DS,AXMOV AH,9LEA DX,INPINT 21H ;提示输入字符串MOV AH,0AHLEA DX,BUFINT 21HMOV AH,2MOV DL,0DHINT 21HMOV DL,0AHINT 21H ;输入字符串LEA SI,BUFMOV DL,[SI+1]MOV ACC,DL ;记录字符串个数MOV SI,2MOV AH,2LA: MOV DL,BUF[SI]CMP DL,'A'JB PUTCMP DL,'Z'JBE PUTCHGPUT:INT 21HJMP LADPUTCHG:ADD DL,32INT 21HLAD:INC SIDEC ACCMOV DH,ACCCMP DH,0JZ EXITJMP LAEXIT:MOV AH,4CHINT 21HCODE ENDSEND START7.请任意输入一个字符串,将其中的英文字母全部删除,并将结果显示在屏幕上。
DATA SEGMENTINP DB 'Please input a string:','$'CHAR DB 0ACC DB 0BUF DB 50DB ?DB 50 DUP(0)DATA ENDSSTACK SEGMENTDB 100 DUP(0)STACK ENDSCODE SEGMENTASSUME CS:CODE,DS:DA TASTART:MOV AX,DA TAMOV DS,AXMOV AH,9LEA DX,INPINT 21H ;提示输入字符串MOV AH,0AHLEA DX,BUFINT 21HMOV AH,2MOV DL,0DHINT 21HMOV DL,0AHINT 21H ;输入字符串LEA SI,BUFMOV DL,[SI+1]MOV ACC,DL ;记录字符串个数MOV SI,2MOV AH,2LA: MOV DL,BUF[SI]CMP DL,'A'JB PUTCMP DL,'Z'JBE LADCMP DL,'a'JB PUTCMP DL,'z'JBE LAD PUT:INT 21HJMP LAD LAD:INC SIDEC ACCMOV DH,ACCCMP DH,0JZ EXITJMP LAEXIT:MOV AH,4CHINT 21HCODE ENDSEND START。