assembly - 如何在汇编中将空格字符添加到字符串中?
问题描述
所以,我必须执行文本更正。如果我在文本/字符串中遇到逗号,我需要验证它之前是否有空格以消除它以及逗号之后是否有空格。如果没有,我需要在逗号后面加一个。我试图这样做,但只有在逗号之前消除空格的部分起作用。当我尝试添加时,我覆盖了一些东西(我在 TD 中看到了),我不知道是什么。
COMMA:
CMP BUFFER[SI],00 ; end of text
JE EXIT
CMP BUFFER[SI],44 ; 44 is the ascii code for comma
JNE NEXTC
CMP BUFFER[SI],44
JE VERIFY
NEXTC:
INC SI
JMP COMMA
VERIFY:
CMP BUFFER[SI-1],20H ; 20 ascii code for space
JNE VERIFY2 ; if it isn't space, I search if the next element after comma is space
CMP BUFFER[SI-1],20H
JE CONDITION
CONDITION:
MOV CL,L
SUB CX,SI
SHR CL,1;
XOR CH,CH;
MOV DI,SI
JMP REMOVESPACE ; I have space before the comma and I eliminate it
REMOVESPACE:
MOV DL, BUFFER[DI]
MOV BUFFER[DI-1],DL ; overwrite the useless space
INC DI
LOOP REMOVESPACE
VERIFY2:
INC SI
CMP BUFFER[SI],20H ; if there is space, I jump to the initial stuff, searching for another comma
JE COMMA
CMP BUFFER[SI],20H
JNE CONDITION2 ; if there isn't, I try to add
CONDITION2:
MOV CL,L ; L is the no of chars in the buffer
SUB CX,SI
SHR CL,1;
XOR CH,CH;
MOV DI,LEN ; LEN also as L but DW
SHR DI,1
JMP ADDSPACE
ADDSPACE:
MOV DL,BUFFER[DI]
MOV BUFFER[DI+1],DL ; here I try to move the elements, obtaining buffer[si+1] free and then move a space to it
DEC DI
LOOP ADDSPACE
MOV BUFFER[SI+1],20H
JMP COMMA
我不知道该怎么办,我认为我无法将所有元素向右移动这一事实存在问题,因为没有缓冲区[L+1] 或其他东西。