This is a simple example that adds two integers, using 32-bit registers EAX and EBX:

#include <iostream>
using namespace std;

int main()
{
	int n, m, Result;
	// How to perform an addition on two integers
	// Result = n + m

	__asm
	{
		MOV n, 202	// Store 202 in n
		MOV m, 125	// Store 125 in m
		MOV EAX, n	// Put the value of n in 32-bit register EAX
		MOV EBX, m	// Put the value of m in 32-bit register EBX
		ADD EAX, EBX	// Add the contents of EBX to the contents of EAX
				// and store the result in register EAX
		MOV Result, EAX	// Retrieve the contents of EAX and put it in Result
	}

	cout << "n = " << n << endl;
	cout << "m = " << m << endl;
	cout << "Result: " << Result << "\n\n";

	return 0;
}

This would produce:

n = 202
m = 125
Result: 327

Press any key to continue...

Home