Y
Y
yii_lover2014-06-20 13:48:01
Programming
yii_lover, 2014-06-20 13:48:01

How to work with c++ strings in Inline Assembler (AT&T gcc syntax compiler)?

In general, I found very little sensible information about Inline Assembler and about AT&T syntax in general.
Material on the wiki
English-language manual
There is a working piece on which I experimented, but did not get the desired result.

#include <iostream>	

int add(int a, int b){
        int res;
        asm("movl %1, %%eax\n\
        inc %%eax\n\
        addl %2, %%eax":"=a"(res):"m"(a),"m"(b));//AT&T
      return res;
}

int main()
{
    using namespace std;

    int a=5, b=5;
    printf("a = %d\nb = %d\n", a, b);
    int c = add(a, b);
    printf("%d + %d + 1 = %d\n", a, b, c);

    system("PAUSE");
    return 0;
}

I tried to get the address using the shift operator, but it turned out that something was wrong.
I seem to have learned how to program in assembler, but in 16-bit (I don’t think the difference is huge)
Where to dig, what to read? Help good people

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2014-06-20
@yii_lover

but didn't get the desired result.

What is your question? What result did you want?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question