汇编程序的数字字符串转换为int

时间:2016-12-05 10:13:26

标签: c string assembly x86

如何在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);
}

1 个答案:

答案 0 :(得分:0)

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

#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;
}
相关问题