Click here to Skip to main content
13,256,123 members (34,371 online)
Click here to Skip to main content


68 bookmarked
Posted 14 Oct 2006

Using Inline Assembly in C/C++

, 14 Oct 2006
This article describes using inline assembly code in your C/C++ program... was it ever difficult for you, it will never be any more!
#include <stdio.h>

int gcd( int a, int b ) {
	int result ;
	/* Compute Greatest Common divisor using Euclid's Algorithm */
	__asm__ __volatile__ ( "movl %1, %%eax;"
						  "movl %2, %%ebx;"
						  "CONTD: cmpl $0, %%ebx;"
						  "je DONE;"
						  "xorl %%edx, %%edx;"
						  "idivl %%ebx;"
						  "movl %%ebx, %%eax;"
						  "movl %%edx, %%ebx;"
						  "jmp CONTD;"
						  "DONE: movl %%eax, %0;" : "=g" (result) : "g" (a), "g" (b)

	return result ;

int main() {
	int first, second ;
	printf( "Enter two integers : " ) ;
	scanf( "%d%d", &first, &second );

	printf( "GCD of %d & %d is %d\n", first, second, gcd(first, second) ) ;

	return 0 ;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
India India
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 15 Oct 2006
Article Copyright 2006 by
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid