本文介绍了在汇编语言中检查空字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是汇编语言的新手.需要明确的是,这是家庭作业.问题是给出了一个char *list,我怎样才能找到哪个字符是字符串的结尾呢?所以我有

I am new to assembly language. To be clear, this is homework. The problem is given a char *list, how can I find which character is the end of the string?So I have

xor ecx, ecx; //counter
loop1:
mov esi, list;
mov eax, [esi + ecx];
cmp eax, 0x00; //check if the character is null
je end;
inc ecx;
jmp loop1;

end:

然而,循环在到达字符串末尾时不会终止.我想知道我做错了什么.我一直在书籍和网上寻找解决方案,但它们看起来都像我所做的.任何帮助将不胜感激!

however, the loop does not terminate when it reaches the end of the string. I wonder what I have done wrong. I have been finding solution in books and online, but they all look like what I did. Any help will be appreciated!

是的,计数器应该在循环之外.

yes, counter should be outside of the loop.

推荐答案

  • 您不应将计数器重置为循环的一部分.
  • 您不应将地址初始化为循环的一部分.
  • 零终止只是一个字节,但您要测试一个完整的双字.
  • 跳转越少,编写的代码越好
  • 把所有这些放在一起,我们得到

    Putting all of this together we get

      mov esi, list
      mov ecx, -1
    loop1:
      inc ecx
      cmp byte [esi + ecx], 0x00; //check if the character is null
      jne loop1;
    

    这篇关于在汇编语言中检查空字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:57