内联程序集 - 检查单词是否为回文
inline assembly - check if word is a palindrome
我正在编写一个简单的程序,它使用内联来检查给定的单词是否是回文。问题是它没有返回正确的答案。在调试过程中,我发现esi寄存器有问题(al
中的值是正确的('a'
),但在bl
中它不是(0)。我不确定我做错了什么。
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char s[] = "arabara";
int sizeofstring = 8; // size of s[]
int x = 0;
int y = 1; //flag when is_palindrome
__asm
{
lea edi, s
mov esi, edi
add esi, sizeofstring
dec esi //point to the last char
mov ecx, sizeofstring
cmp ecx, 1
je is_palindrome //single char is always a palindrome
shr ecx, 1 //divide by 2
nextchar:
mov al, [edi]
mov bl, [esi]
cmp al, bl
jne stop
inc edi
dec esi
loop nextchar
is_palindrome:
mov eax, y
mov x, eax //change flag to 1
stop:
}
cout << x << endl; //shoud print 1 when palindrome
system("pause");
return 0;
}
您将sizeofstring
设置为 8,但字符串"arabara"的长度为 7 个字符。
相关文章:
- 如何检查C ++ STL列表是否为回文?
- C++ - 检查结构数据类型中的单词是否为回文
- 确定用户输入是否为带C++的回文
- 是否可以检查存储在堆栈上的单词是否是回文,而C++中没有任何附加数据结构
- 任何人都可以检查这个回文 c++ 代码是否正确
- 寻找一种更有效的方法来使用 STL 函数检查字符串是否为回文
- 我试图编写一个代码来查找一个单词是否是回文,但它不起作用。怎么了?
- 如何在不使用数学的情况下知道一个数字是否是回文
- 内联程序集 - 检查单词是否为回文
- 检查子数组是否为带指针的回文数组
- 验证字符串是否为回文的函数
- 验证代码以检查数字是否为回文
- 检查数字是否是C++中的回文
- 需要修改堆栈/链表程序以确定单词是否为回文
- 检查数字是否为回文
- 看看我们是否可以获得回文
- 使用不同的函数(C++)测试一个数字是否是回文
- 检查字符串是否为回文
- 目的:检查用户输入的字符串,以确定它是否为回文
- C++-使用堆栈来确定C样式字符串是否为回文