对于我的考试,我必须编写atoi函数,使用汇编语言将字符串转换为整数。这就是我最终的结果。我们的想法是取一串数字减去' 0' 0并得到整数。
int main(int argc, char** argv) {
int iOut = 0;
char pcInp[4] = {'1' , '2' , '3' , '4'};
__asm {
push eax
push ebx
push ecx
push edx
mov eax, pcInp
sub eax, '0'
mov iOut, eax
pop edx
pop ecx
pop ebx
pop eax
}
cout << "The number was processed as: " << iOut << endl;
问题是当我输入例如123时,它输出随机的不同数字。我做错了什么,但我无法弄清楚是什么。我从未参加过集会,我的老师就给了我这个任务。你能不能帮我弄清楚是什么?或许我的整个概念都错了?