标题:
微机原理与接口技术汇编程序-删除字符串开头和结尾的空格
[打印本页]
作者:
2253318110
时间:
2023-5-21 11:29
标题:
微机原理与接口技术汇编程序-删除字符串开头和结尾的空格
该程序实现了将一个字符串开头和结尾的任意多个空格去除然后显示字符串内容。
可以根据需要输入不同的字符串,程序将自动识别并删除开头和结尾的空格。
适合本科阶段学习微机原理与接口技术的同学练习参考。
question_02.png
(39.32 KB, 下载次数: 68)
下载附件
2023-5-21 17:00 上传
;Remove spaces at the beginning and end of a string
DATA SEGMENT
string DB ' a string for testing. ',0
length DW $-string ;length of the string
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, string
BEGIN: ;Set beginning pointer of the new string
CMP [SI], ' ' ;Find spaces, skip them
JNE NEXT
INC SI
JMP BEGIN
NEXT: ;Shift DI to the end of the initial string
LEA DI, string
MOV AX, length ;Load length of the string to AX
ADD DI, AX
SUB DI, 2 ;Move DI to the end of the string
THIRD: ;Shift DI to the end of the new string
CMP [DI], ' '
JNE LAST
DEC DI
JMP THIRD
LAST: ;display the new string on screen
INC DI
MOV byte ptr[DI], '0' ;string ends with 0
INC DI
MOV byte ptr[DI], '
MOV AH, 09H
MOV DX, SI ;Set offset adress
INT 21H
CODE ENDS
END START
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1