我正在编写一个汇编程序来计算大写字母A,B,C和小写字母a,b,c的数量。我遇到的问题是如果比较正确,程序不会转到标签。我已经尝试将char存储在注册表中,但同样的事情仍在继续。
#include<iostream>
#include<string>
using namespace std;
void readData(), readChar(), printData();
int i = 0, a = 0, b = 0, c = 0;
char ch;
string str;
int main()
{
_asm
{
call readData;
whileloop:
call readChar;
cmp i, 10;
je done;
jne toLoop;
toLoop:
cmp ch, 'A';
je addA;
cmp ch, 'B';
je addB;
cmp ch, 'C';
je addC;
cmp ch, 'a';
je addA;
cmp ch, 'b';
je addB;
cmp ch, 'c';
je addC;
addA:
inc a;
jmp whileloop;
addB:
inc b;
jmp whileloop;
addC:
inc c;
jmp whileloop;
done:
call printData;
}
system("pause");
return 0;
}
void readData()
{
cout << "Enter the sentence: ";
cin >> str;
}
void readChar()
{
ch = str[i];
i++;
}
void printData()
{
cout << "A = " << a << "\nB = " << b << "\nC = " << c << endl;
}