help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with inline Assembler


From: Sebastian Waschik
Subject: Re: help with inline Assembler
Date: Wed, 05 Aug 2009 01:05:39 +0200
User-agent: Gnus/42.00 (Gnus v42.0.0) Emacs/42.0

Hello,
llueveYescampa <edgarfblack@gmail.com> writes:

> Hi all,
>
> A couple of  years ago, working with OpenWatcom for Windows, I was
> able to wrote the inline assembly code shown below. I spent a while
> reading and by trail an error I made it work.
>
> I was trying to test the efficiency of the "inner_product()" function
> in C++.
>
> Now I am working in Linux and I would like to compile it with g++.
>
> Is the inline assembly of g++ similar?
> Can some of this code be reused in g++?

inline assembler of gcc is different.  For example all register are
prefixed by "%".  All constants are prefixed by "$".

See: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

Here a simple example
#include <iostream>

int function(void)
{
  int result;
  asm(
      "mov $0x2, %%eax\n\t"
      "mov $3, %%ebx\n\t"
      "add %%ebx, %%eax\n\t"
      "mov %%eax, %0\n\t"
        : "=r"(result)
        :
        : "%eax", "%ebx"
        );
  return result;
}

int main(void)
{
  std::cout << function() << std::endl;
  return 0;
}

Viele Grüße
Sebastian Waschik





reply via email to

[Prev in Thread] Current Thread [Next in Thread]