I am trying to do the equivalent of b = ++a; with inline assembly, but I'm getting strange values in my variables after executing the code. I am using clang++ (g++ compatible) to compile inline assembly. Here is what I get so far:
#include <iostream>
using std::endl;
using std::cout;
int main()
{
    uint64_t a = 0;
    uint64_t b = 0;
    asm volatile(
    "pushq %%rbp;"
    "movq %%rsp, %%rbp;"
    "movl $0, -4(%%rbp);"
    "movl $0, -8(%%rbp);"
    "addq $1, -4(%%rbp);"
    "mov -4(%%rbp), %%rax;"
    "mov %%rax, -8(%%rbp);"
    "mov -4(%%rbp), %0;"
    "mov -8(%%rbp), %1;"
    "movq %%rbp, %%rsp;"
    "popq %%rbp"
    :"=r" (a), "=r" (b)
    :
    :"%rax", "%rbp", "%rsp"
    );
    cout << "a = " << a << ", b = " << b << endl;
    return 0;
}
 
    