第二,您的是字母"分支是不正确的(例如,字母"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 stringfilterString: 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 retwith writing this assembly code i cant get this option to work with the removing a non character letter. it will either iterate through the string with all the comparisons and then display the same string with no non characters removed.I'm trying to get the letter characters into a tempString that i can then move to edx to be displayed.it takes in a string and removes all non letter charactersthen displays the new string using another procedure that uses writestring and 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.codepush esicall option5L3:mov al, byte ptr [edx+esi]cmp al, 41hjb notlettercmp al, 5Ahja notlettercmp al, 61hjb notlettercmp al,7Ahja notlettermov byte ptr [edx+esi], alnotletter:inc esiloop L3pop esicall option5call waitmsgoption3 ENDP 解决方案 First, think of this as copying from one place to the same place; where bytes that need to be ignored are not copied. You need 2 registers for this - one to keep track of where to get the next byte (e.g. maybe esi), and one to keep track of where to store the next byte/letter (e.g. maybe edi).Second, your "is it a letter" branches aren't right (e.g. the letter 'A' or the value 0x41 will be less than the letter 'a' or the value 0x61). It needs to be more like: 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:For example (NASM):;Inputs:; ecx Length of original string; esi Address of original string;;Outputs; edi Length of new string; ebx Address of new stringfilterString: 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 这篇关于需要从汇编中的字符串中删除所有非字母元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 10:30