Results 1 to 6 of 6
  1. #1
    samlarenskoog's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    104
    Reputation
    25
    Thanks
    57
    My Mood
    Cheerful

    Simple add function

    Hello guys, I am trying to learn asm and I am in need of some help. How come this does not work?
    Code:
    #include <stdio.h>
    #include <iostream>
    int add(int num1, int num2);
    using namespace std;
    int main(void)
    {
    	int result = add(3, 2);
    	cout << result;
    	system("pause");
    }
    
    int add(int num1, int num2)
    {
    	int result = 0;
    	__asm
    	{
    		mov result, offset num1
    		push result
    		mov result, offset num2
    		push result
    	}
    	return result;
    }
    As you can see I am very new to asm.

  2. #2
    FatAssHacker123's Avatar
    Join Date
    Jul 2011
    Gender
    male
    Location
    Who's asking?
    Posts
    524
    Reputation
    46
    Thanks
    128
    My Mood
    Hungover
    I'm not great at asm and even worse on mixed programming but I can tell you this: offset means you're going to be getting the memory addresses for num1 and num2. You should be pushing the values themselves, I think. Try using this:

    mov result, num1
    add result, num2

    or

    push num1
    push num2
    fadd
    pop result
    Also, what error are you getting?

    Edit: Right now I can't test the code but later I'll test at home and try to help you. You should also look for assembly command sheets, they're very helpful
    Last edited by FatAssHacker123; 08-05-2016 at 05:40 AM.

  3. #3
    FatAssHacker123's Avatar
    Join Date
    Jul 2011
    Gender
    male
    Location
    Who's asking?
    Posts
    524
    Reputation
    46
    Thanks
    128
    My Mood
    Hungover
    Quote Originally Posted by samlarenskoog View Post
    Your question
    I have tested this at home. I came up with this code:
    Code:
    #include "stdafx.h"
    #include <stdio.h>
    #include <iostream>
    
    using namespace std;
    
    int add(int num1, int num2)
    {
    	int result;
    	__asm
    	{
    		xor eax, eax;
    		mov eax, num1;
    		add eax, num2;
    		mov result, eax;		
    	}
    	return result;
    }
    
    int main()
    {
    	int result, a, b;
    	cout << "Variable 1: ";
    	cin >> a;
    	cout << "Variable 2: ";
    	cin >> b;
    	result = add(a, b);
    	cout << result << endl;
    	system("pause");
    }
    I don't really know why it doesn't work as I never did c++ and asm together but the error I was getting was improper argument type on both mov lines. By looking at my code you can tell that what was wrong was using result in the mov with num1 and 2. Also, as I said before, offset means the address of the variable and not the actual value stored in that address. I'm not an expert in this but I hope I could help.

  4. #4
    FatAssHacker123's Avatar
    Join Date
    Jul 2011
    Gender
    male
    Location
    Who's asking?
    Posts
    524
    Reputation
    46
    Thanks
    128
    My Mood
    Hungover
    I forgot to explain what XOR EAX, EAX is for, it will set EAX to 0, or in other words, clear the address

  5. #5
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by FatAssHacker123 View Post
    I forgot to explain what XOR EAX, EAX is for, it will set EAX to 0, or in other words, clear the address
    Why would you want to do that if you move something into eax anyways right after?

    Also, why are you not using naked functions?
    Last edited by WasserEsser; 08-20-2016 at 12:04 PM.

  6. #6
    javalover's Avatar
    Join Date
    May 2016
    Gender
    male
    Posts
    167
    Reputation
    10
    Thanks
    532
    Quote Originally Posted by samlarenskoog View Post
    Hello guys, I am trying to learn asm and I am in need of some help. How come this does not work?
    Code:
    #include <stdio.h>
    #include <iostream>
    int add(int num1, int num2);
    using namespace std;
    int main(void)
    {
    	int result = add(3, 2);
    	cout << result;
    	system("pause");
    }
    
    int add(int num1, int num2)
    {
    	int result = 0;
    	__asm
    	{
    		mov result, offset num1
    		push result
    		mov result, offset num2
    		push result
    	}
    	return result;
    }
    As you can see I am very new to asm.
    1. Which compiler are you using?
    2. In GCC you use asm(), not asm{}.
    3. If you are using GCC, you will also need to do a manual clobbering. For VC++, you won't.

  7. The Following User Says Thank You to javalover For This Useful Post:

    Nine11 (02-13-2017)

Similar Threads

  1. [Source Code] Simple OPK Function ( Only Against Bots )
    By Hacker Fail in forum Counter-Strike 2 Coding & Resources
    Replies: 8
    Last Post: 07-26-2016, 12:31 PM
  2. [Source Code] HighRise Simple [ D3D Functions + Hook ]
    By OpKilts in forum Combat Arms Hack Coding / Programming / Source Code
    Replies: 12
    Last Post: 07-31-2013, 09:11 AM
  3. [Help] Add functions on Karraka Base
    By Mike Shinoda in forum WarRock Hack Source Code
    Replies: 21
    Last Post: 05-10-2011, 10:16 AM
  4. [Help Request] Add Functions
    By rapha15br in forum Combat Arms BR Coding Help
    Replies: 10
    Last Post: 04-22-2011, 07:17 PM
  5. [Release] Dawm Nomenu v1.5 Undetected 3-2-2010..add new function
    By maxpayne in forum WarRock - International Hacks
    Replies: 84
    Last Post: 03-06-2010, 11:59 AM