gpt4 book ai didi

c - 将数字字符串汇编成 int

转载 作者:行者123 更新时间:2023-11-30 19:36:21 26 4
gpt4 key购买 nike

如何使用 C++ 中的 IA-32 汇编器将数字(小数)字符串转换为整数(二进制)?

这是我需要的外壳。

#include <stdio.h>
int main(int argc, char** argv) {

int iOut = 0;
char* pcInp;

if (argc < 2) {
printf("Mssing parameter: number\n");
return(0);

}

pcInp = argv[1];

_asm {

push aex
push ebx
push ecx
push edx

//code here

pop edx
pop ecx
pop ebx
pop eax


}

printf("Number was processed as %d\n", iOut);
}

最佳答案

解决了,也许其他人会需要这个。

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(int argc, char** argv)
{
int Lenght;
int pirmasSkaicius = 0;
int antrasSkaicius = 0;

int treciasSkaicius = 0;
int ketvirtasSkaicius = 0;

int rez = 0;
char * numbEntered = new char[10];
if (argc < 2) {
printf("No parameter: number\n");
return(0);
}
numbEntered = argv[1];
Lenght = strlen(numbEntered);
cout << "Lenght: " << Lenght << endl;


__asm {

push eax
push ebx
push ecx
push edx

add treciasSkaicius, eax
add ketvirtasSkaicius, edx
xor eax, eax
xor edx, edx

mov ecx, numbEntered

mov al, byte ptr[ecx]
sub eax, 48
mov ebx, 1000
imul eax, ebx
mov pirmasSkaicius, eax

inc ecx
xor eax, eax
xor edx, edx

mov al, byte ptr[ecx]
sub eax, 48
mov ebx, 100
imul eax, ebx
mov antrasSkaicius, eax

xor eax, eax
xor edx, edx
inc ecx

mov al, byte ptr[ecx]

sub eax, 48
mov ebx, 10
imul eax, ebx
mov treciasSkaicius, eax

inc ecx
xor eax, eax
xor edx, edx
mov al, byte ptr[ecx]

sub eax, 48
mov ketvirtasSkaicius, eax
add edx, pirmasSkaicius
add edx, antrasSkaicius
add edx, treciasSkaicius
add edx, ketvirtasSkaicius
mov rez, edx

pop edx
pop ecx
pop ebx
pop eax

}
cout << "Processed: " << rez << endl;
cout << "Pieces as: " << pirmasSkaicius << " " << antrasSkaicius << " " << treciasSkaicius << " " << ketvirtasSkaicius << endl;

system("pause");
return 0;
}

关于c - 将数字字符串汇编成 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40971814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com