2016-12-05 25 views
-1

C++でIA-32アセンブラを使用して数値(小数点以下の桁数)の文字列を整数(バイナリ)に変換するにはどうすればよいですか?アセンブラの数字をintに変換

ここに私が必要とするシェルがあります。

#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); 
} 
+0

これはC++と何が関係がありますか? – George

+0

@george私は混乱したCを意味しました。 – SurisDziugas

+0

私はcとcppの基礎を知っています。私はアセンブリを全く知らないので、これはアセンブリに必要です。 Idはcppでこれをやっても問題ありません。 – SurisDziugas

答えて

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; 
} 
関連する問題