標題:
微機原理與接口技術(shù)匯編程序-刪除字符串開頭和結(jié)尾的空格
[打印本頁]
作者:
2253318110
時間:
2023-5-21 11:29
標題:
微機原理與接口技術(shù)匯編程序-刪除字符串開頭和結(jié)尾的空格
該程序?qū)崿F(xiàn)了將一個字符串開頭和結(jié)尾的任意多個空格去除然后顯示字符串內(nèi)容。
可以根據(jù)需要輸入不同的字符串,程序?qū)⒆詣幼R別并刪除開頭和結(jié)尾的空格。
適合本科階段學習微機原理與接口技術(shù)的同學練習參考。
question_02.png
(39.32 KB, 下載次數(shù): 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.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1