Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» ~=?{The future is here, TastyExploit officially open to the public}?=~
Tue Mar 02, 2010 11:00 pm by Dami

» My first aa script
Tue Mar 02, 2010 7:00 am by wafflemaster

» the real story behind Maverin
Tue Mar 02, 2010 1:33 am by SoundOfDeat

» Random spam
Mon Mar 01, 2010 11:52 pm by Danny1994

» [Request] EMS v56 Exe
Mon Mar 01, 2010 12:39 am by Dami

» [Blacklist] NX-Trading Blacklist.
Mon Mar 01, 2010 12:38 am by Danny1994

» I have a question regarding the meso farmer
Sat Feb 27, 2010 10:30 pm by Dami

» What are you listening to now?
Sat Feb 27, 2010 7:57 pm by Noname111111

» Video(s) Of The Day
Sat Feb 27, 2010 7:37 pm by Noname111111

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Affiliates
free forum
 



[C++ Tutorial] Calculator - ASM

Go down

[C++ Tutorial] Calculator - ASM

Post by Guest on Thu Oct 22, 2009 12:13 am

Hello, and welcome to this tutorial on how to make a Calculator in C++
This time with ASM (Assembly) the way we write this is called Inline Assembly
And in C++ you write Assembly codes in "Intel Assembly" language.
Theres also "T&AT" Language but u cant write with that in C++.

Now if u havent read the First Calculator tutorial, i suggest u go read it now, before you continue.
http://damiproductions.darkbb.com/programming-tutorials-f18/c-tutorial-calculator-t237.htm


This time were gonna make a Calculator (Also with basic C++ commands as last time, just this time, the calculating are written in Assembly Code)

So here we go with the code;

Code:
//###############################
//## Made By Caroe/HellsMinion ##
//###############################

//ASM can be rather difficult, so please pay attention to the ASM parts.


//This out includes of libraries
//This makes the program recognize the codes we write.
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//Makes an invisible "std::" before all our "cout", "cin", and "endl"
//If we didnt have this code, we would have to write following;
//std::cout << "TEXT" << std::endl
//or
//std::cin >> INTEGER HERE
using namespace std;

//Defines a bool (programRunning) as true
//We use this in main function
//Also used a "End Program" choice in Operation List in Calculator.
bool programRunning = true;

//READ THIS!!
//Read this source in this Order:
//1. Main Function (Read Main Function first)
//2. Menu Function (Read The Menu second)
//3. Calculator Function (Read The Calculator last)
//Thanks :)

//This is the Calculator Function (This calculates)
void Calculator()
{   int x, y, z; //Integers x y and z (Used a number1, number2, sum)
   int O, K; //Integers O and K (Used a choice1, choice2)
//Label used, if we wanna return to the calculator.
Re:
   
   //Write "First Value: "
   cout << "First Value: ";
   //Looks at the number u wrote after "First Value: " and remembers it as "x"
   cin >> x;
   //Extra hook (Used to make sure the program hooks it)
   cin, x;

   //Writes "Second Value: "
   cout << "Second Value: ";
   //Same as "x" this one is just remembered as "y"
   cin >> y;
   //Extra hook (To make sure program hooks input as y.
   cin, y;

   //Filler (Makes an empty line)
   cout << endl;

   //Clears screen before we continue, just to make it easier to look at.
   system("cls");

   //Now that we entered our 2 numbers to be calculated, we have to select an operation
   //This operation is wether the 2 numbers (x & y) are gonna be plussed, minused, multiplyed or Divided.
   cout << "Select Operation." << endl;
   //Writes "Type 1 for Plus" (This is a choice)
   cout << "Type 1 for Plus" << endl;
   //Writes "Type 2 for Minus" (This is a choice)
   cout << "Type 2 for Minus" << endl;
   //Writes "Type 3 for Divide" (This is a choice)
   cout << "Type 3 for Divide" << endl;
   //Writes "Type 4 for Multiply" (This is a choice)
   cout << "Type 4 for Multiply" << endl;
   //Filler (Makes an empty line)
   cout << endl;
   //Writes "Input: "
   cout << "Input: ";
   //Hooks the input as "O"
   cin >> O;
   //Extra hook.
   cin, O;
   //Filler (Makes an empty line)
   cout << endl;

   //Switch function of the integer "O" (Like in the Menu Function)
   //That was just a switch with and integer "C".
   //A switch function has "cases" (Case 1, Case 2, or even more)
   //U can make a switch with 1 case, or u can make a switch with 99999 cases)
   //Theres no number of available cases.
   switch(O)
   {
   
   //Case 1 (If Integer "O" was '1' (This is Plus)
   case 1:
   {
      //Now you write the asm code
      __asm
      {
      //I use a method when i write assembly.
      //when its example: "mov eax, a"
      //I say it like this in my head; "mov TO eax, a"
      //I add a "TO" in my head.
      //The first thing said is the PLACE TO PUT the second thing said.
      mov eax, x //Means move x to eax
      add eax, y //Means add y to eax.
      mov z, eax //Means move eax to z
      //What we did here was:
      //1. we made X into "EAX"
      //2. we added Y to "EAX"
      //3. we made the EAX into "Z"
      //Z is now the complete value.
      }
      //Clears the Screen
      system("cls");
      //Writes "<x> + <y>" (This will show as numbers.)
      //if x is 3, and y is 4 it will say "3 + 4"
      cout << x << " + " << y << endl;
      //Writes "Sum is: <z>" (This will show as a number)
      //if z is 7, it will write "Sum is: 7"
      cout << "Sum is: " << z << endl;
      //Pauses program (Press any key to continue)
      system("pause");
      //Clears Screen.
      system("cls");
   }

   //Case 2 (If Integer "O" was '2' (This is Minus)
   case 2:
   {
      //Now you write the asm code
      __asm
      {
      //I use a method when i write assembly.
      //when its example: "mov eax, a"
      //I say it like this in my head; "mov TO eax, a"
      //I add a "TO" in my head.
      //The first thing said is the PLACE TO PUT the second thing said.
      mov eax, x //Means move X to "EAX"
      sub eax, y //Means subtract (Minus) "EAX" with Y
      mov z, eax //Means move "EAX" to Z
      //What we did here:
      //1. We made X into "EAX"
      //2. We minussed Y into "EAX"
      //3. We made EAX into Z
      //Z is now the finished value.
      }
      //Clears Screen
      system("cls");
      //Writes "<x> - <y>" (This will show as numbers.)
      //if x is 4, and y is 3 it will say "4 - 3"
      cout << x << " - " << y << endl;
      //Writes "Sum is: <z>" (This will show as a number)
      //if z is 1, it will write "Sum is: 1"
      cout << "Sum is: " << z << endl;
      //Pauses prgoram (Press any key to continue)
      system("pause");
      //Clears Screen
      system("cls");
   }

   //Case 3 (If Integer "O" was '3' (This is Divide)
   case 3:
   {
      
      //Now you write the ASM code
      __asm
      {
      //#####################################
      //## I HAVENT WROTE THE DIVIDE CODE! ##
      //## THIS IS FOR YOU TO SOLVE URSELF ##
      //#####################################
      }
      //Clears Screen.
      system("cls");
      //Writes "<x> / <y>" (This will show as numbers.)
      //if x is 4, and y is 2 it will say "4 / 2"
      cout << x << " / " << y << endl;
      //Writes "Sum is: <z>" (This will show as a number)
      //if z is 2, it will write "Sum is: 2"
      cout << "Sum is: " << z << endl;
      //Pauses program (Press a key to continue)
      system("pause");
      //Clears Screen
      system("cls");
   }

   //Case 4 (If Integer "O" was '4' (This is Multiply)
   case 4:
   {
   
      //Now you write the asm code
      __asm
      {
      //I use a method when i write assembly.
      //when its example: "mov eax, a"
      //I say it like this in my head; "mov TO eax, a"
      //I add a "TO" in my head.
      //The first thing said is the PLACE TO PUT the second thing we said.
      mov eax, x //Means move X to "EAX"
      mov ebx, y //Means move Y to "EBX"
      imul ebx //Means Multiply with EBX (EAX with EBX)
      mov z, eax //Moves "EAX" to Z
      //What we did here:
      //1. We made X into "EAX"
      //2. We made Y into "EBX"
      //3. We Multiplied with "EBX" (EAX with EBX)
      //4. We made "EAX" into Z
      //Z is now the finished value.
      }
      //Clears Screen
      system("cls");
      //Writes "<x> * <y>" (This will show as numbers.)
      //if x is 4, and y is 3 it will say "4 * 3"
      cout << x << " * " << y << endl;
      //Writes "Sum is: <z>" (This will show as a number)
      //if z is 12, it will write "Sum is: 12"
      cout << "Sum is: " << z << endl;
      //Pauses program (Press any key to continue)
      system("pause");
      //Clears Screen
      system("cls");
   }
   }

   //Writes "Select Operation."
   //After this it write "Type <NUMBER> To <Function>
   //Your can choose between the operations.
   cout << "Select Operation." << endl;
   cout << "Type 1 To Re-enter The Calculator" << endl;
   cout << "Type 2 To Go To The Menu" << endl;
   cout << "Type 3 To Exit Program." << endl;
   //Filler (Makes an empty line)
   cout << endl;
   //Writes "Input: "
   cout << "Input: ";
   //Hooks ur Input and remembers it as "K"
   cin >> K;
   //Extra Hook (To make sure u hooked it.
   cin, K;

   switch(K)
   {
   //Case 1 (If Input at Integer "K" was '1'. This is "Re-enter The Calculator")
   case 1:
   {
   //Clears the screen
   system("CLS");
   //Goes to the label "Re" that we made in the start of Calculator Function.
   goto Re;
   }

   //Case 2 (If Input at Integer "K" was '2'. This is "Go To Menu")
   case 2:
   {
   //Nothing here, the program goes to Main Function if theres no "Repeating End" on a function
   //This means that if nothing happens here, and it comes to end of Calculator, then...
   //Then it will just go to Main Function for new instructions.
   //But the Main Function is in a "While Loop" so it will give only 1 instruction:
   //"Go To Menu"
   }

   //Case 3 (If Input at Integer "K" was '3'. This is "Exit Program")
   case 3:
   {
   programRunning = false;
   //Again this one only sets "programRunning" boolean to false.
   //As theres nothing after this it quits the switch function.
   //Now after switch function the calculator function ends, so goes to Main Function
   //But now the "programRunning" boolean is false, so Main Function will skip the While Loop
   //And then it will go to "return EXIT_SUCCESS" and program will close.
   }
   }
}

//Our Menu (Main function "links" to this.)
void Menu()
{   int C; //Integer Choice

   //Clears screen-
   system("cls");
   //Write "Welcome To The Menu"
   cout << "Welcome To The Menu" << endl;
   //Makes an empty line.
   cout << endl;
   //Write "Select Operation"
   cout << "Select Operation." << endl;
   //Writes "Type 1 For Calculator" (This is a choice on operations)
   cout << "Type 1 For Calculator." << endl;
   //Makes an empty line.
   cout << endl;
   //Writes "Input: "
   cout << "Input: ";
   //This one hook what u wrote after "Input: "
   cin >> C;
   //This does same as "cin >> C;" just better effect with 2 of them (Else it might skip)
   cin, C;

   //Switch function of the integer "C" (Choice)
   switch(C)
   {
   //Case 1 (Means if the input of "C" was '1')
   //This case is Calculator.
   case 1:
      {
      //Clears Screen.
      system("cls");
      //Goes to Calculator.
      Calculator();
      }
   }
}

//Main function.
int main()
{
   //Makes Title of window to "Calculator (asm)"
   system("TITLE Calculator (asm)");
   //Give our text a color (7 = the color)
   //You can edit this if u like, and play a little with it ;D
   system("COLOR 7");

//While our boolean (programRunning) is true program will go to Menu
//But if programRunnig has the value FALSE our program will end, bcuz it skips the WHILE FUNCTION
while (programRunning)
{
   //Goes to Menu (a void we have a bit up)
   Menu();
}
//Return to an exit point in program (Only if while menu is skipped)
return EXIT_SUCCESS;
}

No reason to write about it, alot of comments inside the text. (Also noobfriendly comments)

Post if u have any questions. Very Happy

HINT:: Notice i've removed the divide part. You are to code that on your own (Post if u succeed, so i can know if its a OK niveau, or if its too hard)

Guest
Guest


Back to top Go down

Re: [C++ Tutorial] Calculator - ASM

Post by Dureitor on Thu Oct 22, 2009 3:21 pm

nice tutorial,

Dureitor
New member
New member

Posts : 38
Join date : 2009-08-17

Back to top Go down

Re: [C++ Tutorial] Calculator - ASM

Post by Dami on Fri Oct 23, 2009 2:56 pm

Next time you have questions about jumps and codecaves, create another topic for it.
avatar
Dami
Dragon
Dragon

Posts : 1414
Join date : 2009-08-10
Age : 29
Location : Finland

Back to top Go down

Re: [C++ Tutorial] Calculator - ASM

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum