Below is a basic Calculator i made using Inline ASM in C++. The functions include addition, subtraction, division and multiplication.
Hope it helps a littleCode:/* Basic Asm Calculator Showing how to code some simple functions in C++ using Inline Asm! Just on the Asm Functions you do not need to have the ';' at the end of each line I have just come custom to it but it make no great deal! */ #include <windows.h> #include <iostream.h> //Function Prototypes need to be declared the 'main' //function however does not need to be declared int Add(int x, int y); int Sub(int x, int y); int Div(int x, int y); int Mul(int x, int y); int main () { int func; //Function to use, see the switch statement int x,y; //x and y = number 1 and number 2 respectively :) bool finish=false; //just a boolean so the program won't close ;) while (finish==false) //loop begins so program won't exit when done :D { cout<<"1:Add, 2:Sub, 3:Div, 4:Mul\n"; cout<<"Please enter a number to represent the function\n"; cin>>func; //enter number representing the proper function cout<<"Enter first number\n"; cin>>x; //enter first number cout<<"Enter second number\n"; cin>>y; //enter second number switch(func) //remeber func is an integer type { case 1: cout<<Add(x,y)<<endl; //if func = 1 then Add x and y break; case 2: cout<<Sub(x,y)<<endl; //if func = 2 then subtract x and y break; case 3: cout<<Div(x,y)<<endl; //if func = 3 then divide x and y break; case 4: cout<<Mul(x,y)<<endl; //if func = 4 then multiply x and y break; } } return 0; } int Add(int x, int y) { __asm { mov eax,x; mov ebx,y; add eax,ebx; mov x,eax; } return x; } int Sub(int x, int y) { __asm { mov eax,x; mov ebx,y; sub eax,ebx; mov x,eax; } return x; } int Div(int x, int y) { __asm { mov eax,x; mov ecx,y; sub edx,edx; div ecx; mov x,eax; } return x; } int Mul(int x, int y) { __asm { mov eax,x; mov ebx,y; mul ebx; mov x,eax; } return x; }![]()




Reply With Quote