Во-первых, думайте об этом как о копировании из одного места в одно и то же место;где байты, которые нужно игнорировать, не копируются. Для этого вам нужно 2 регистра - один для отслеживания того, где взять следующий байт (например, может быть esi
), и один для отслеживания того, где хранить следующий байт / букву (например, edi
).
Во-вторых, ваши ветки "это ли буква" не верны (например, буква 'A' или значение 0x41 будет меньше, чем буква 'a' или значение 0x61). Это должно быть больше похоже на:
cmp al,'A' ;Is the value too low to be any letter?
jb .notLetter ; yes
cmp al,'z' ;Is the value too high to be any letter?
ja .notLetter ; yes
cmp al,'Z' ;Is the value low enough to be a capital letter?
jbe .isLetter ; yes
cmp al,'a' ;Is the value high enough to be a lower case letter?
jae .isLetter ; yes
; no, not a letter
.notLetter:
Например (NASM):
;Inputs:
; ecx Length of original string
; esi Address of original string
;
;Outputs
; edi Length of new string
; ebx Address of new string
filterString:
mov edi,esi ;edi = address to store string (same address as original string)
mov ebx,esi ;ebx = address of both strings (used later)
jecxz .done ;Do nothing if the original string has zero length
cld
.nextByte:
lodsb ;AL = next byte, ESI incremented
cmp al,'A' ;Is the value too low to be any letter?
jb .doneByte ; yes, not a letter
cmp al,'z' ;Is the value too high to be any letter?
ja .doneByte ; yes, not a letter
cmp al,'Z' ;Is the value low enough to be a capital letter?
jbe .isLetter ; yes, it's a capital letter
cmp al,'a' ;Is the value high enough to be a lower case letter?
jb .doneByte ; no, not a letter
; yes, it's a lower case letter
.isLetter:
stosb ;Store AL at EDI, and increment EDI
.doneByte:
loop .nextByte
.done:
sub edi,ebx ;edi = length of new string
ret