Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 需要从程序集中的字符串中删除所有非字母元素_Assembly_X86 - Fatal编程技术网

Assembly 需要从程序集中的字符串中删除所有非字母元素

Assembly 需要从程序集中的字符串中删除所有非字母元素,assembly,x86,Assembly,X86,编写此汇编代码时,我无法使用此选项删除非字符字母。它将遍历包含所有比较的字符串,然后在不删除非字符的情况下显示相同的字符串。 我试图将字母字符转换成tempString,然后移动到edx进行显示 它接收字符串并删除所有非字母字符 然后使用另一个使用writestring和register edx的过程显示新字符串 ;// ------------------------------------------------------------------------------ option3

编写此汇编代码时,我无法使用此选项删除非字符字母。它将遍历包含所有比较的字符串,然后在不删除非字符的情况下显示相同的字符串。 我试图将字母字符转换成tempString,然后移动到edx进行显示

它接收字符串并删除所有非字母字符
然后使用另一个使用writestring和register edx的过程显示新字符串


;// ------------------------------------------------------------------------------
option3 PROC
;// Description: removes all non-letter elements. There is no requirement for
;// option2 to have been executed.
;// Receives: ecx - length of string
;// edx - offset of string
;// ebx - offset of string length variable
;// esi preserved
;// Returns: nothing, but the string will have all non-letter elements removed

.data


.code

push esi
call option5

L3:
mov al, byte ptr [edx+esi]

cmp al, 41h
jb notletter
cmp al, 5Ah
ja notletter
cmp al, 61h
jb notletter
cmp al,7Ah
ja notletter


mov byte ptr [edx+esi], al

notletter:
inc esi
loop L3


pop esi
call option5
call waitmsg

option3 ENDP


首先,将其视为从一个地方复制到同一个地方;其中不复制需要忽略的字节。为此,您需要两个寄存器-一个用于跟踪下一个字节的位置(例如,可能
esi
),另一个用于跟踪下一个字节/字母的存储位置(例如,可能
edi

其次,您的“is it a letter”分支不正确(例如,字母“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):


“我需要帮助”太模糊了。您遇到的具体问题是什么?您当然可以将字母检查优化为
或al,0x20
/
子al,'a'
/
cmp al,'z'-'a'/ja。非字母
。(或者对AL的副本这样做,因为这是破坏性的。)(嗯,我认为我们可以调整它,使用
lea-edx,[eax-'a']
,而不是单独的
mov
,除非这会引入误报。)
;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