用汇编语言模仿上述程序完成去除字符串中的某个字符提示输入字符串;输入任意字符串string,点击Enter结束输入;提示输入字符;输入任意字符ch,点击Enter结束输入将字符串中字符ch去除,输出变化后的字符串string2点击Enter程序退出
时间: 2024-03-15 10:42:23 浏览: 69
以下是汇编语言模仿上述程序完成去除字符串中的某个字符的代码,已加上中文注释:
DATA SEGMENT
; 请根据需要修改提示信息
STRING1 DB '请输入一个字符串:',13,10,'$'
STRING2 DB '请输入需要删除的字符:',13,10,'$'
STRING3 DB '删除后的字符串为:',13,10,'$'
BUF1 DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'$'
BUF2 DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'$'
DATA ENDS
STACKS SEGMENT PARA STACK
DW 128 DUP(0)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES, DS:DATA, SS:STACKS
START:
MOV AX, DATA
MOV DS, AX
; 提示用户输入一个字符串
LEA DX, STRING1
CALL DISPSTRING
; 读取用户输入的字符串
LEA DX, BUF1
CALL READSTRING
; 提示用户输入需要删除的字符
LEA DX, STRING2
CALL DISPSTRING
; 读取用户输入的字符
CALL READCHARACTER
MOV BL, AL
; 删除字符串中的指定字符
LEA SI, BUF1
LEA DI, BUF2
MOV CX, 0
LOOP1:
MOV AL, [SI]
CMP AL, BL
JZ SKIP
MOV [DI], AL
INC DI
INC CX
SKIP:
INC SI
LOOP LOOP1
; 输出删除指定字符后的字符串
LEA DX, STRING3
CALL DISPSTRING
LEA DX, BUF2
CALL PRINT
; 程序结束
MOV AH, 4CH
INT 21H
; 读取字符串
READSTRING PROC
LEA SI, BUF1
MOV CX, 0
MOV AH, 01H
READSTRING_LOOP:
INT 21H
CMP AL, 13
JE READSTRING_EXIT
MOV [SI], AL
INC SI
INC CX
JMP READSTRING_LOOP
READSTRING_EXIT:
MOV [SI], '$'
RET
READSTRING ENDP
; 读取字符
READCHARACTER PROC
MOV AH, 01H
READCHARACTER_LOOP:
INT 21H
CMP AL, 13
JE READCHARACTER_EXIT
MOV BL, AL
JMP READCHARACTER_LOOP
READCHARACTER_EXIT:
RET
READCHARACTER ENDP
; 显示字符串
DISPSTRING PROC
MOV AH, 09H
INT 21H
RET
DISPSTRING ENDP
; 输出字符串
PRINT PROC
LEA SI, BUF2
MOV CX, 0
PRINT_LOOP:
MOV DL, [SI]
CMP DL, '$'
JE PRINT_EXIT
MOV AH, 02H
INT 21H
INC SI
JMP PRINT_LOOP
PRINT_EXIT:
RET
PRINT ENDP
CODES ENDS
END START
阅读全文