Answer the question
In order to leave comments, you need to log in
What's wrong with nested assembler code?
I work on a virtual machine, in ubuntu. Started working in gcc. I took an assembler and tried to make an adder. But something went wrong.
The code:
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char** argv)
{
int a, b, c;
cin >> a;
cin >> b;
asm (
"mov a, %eax \n\t"
"mov b, %ebx \n\t"
"add %eax, %ebx \n\t"
"mov %ebx, c \n\t"
);
printf("%d", c);
return 0;
}
Answer the question
In order to leave comments, you need to log in
asm ( "mov a, %eax \n\t" "mov b, %ebx \n\t" "add %eax, %ebx \n\t" "mov %ebx, c \n\t" );
asm (
"mov %[a], %%eax \n\t"
"mov %[b], %%ebx \n\t"
"add %%eax, %%ebx \n\t"
"mov %ebx, %[c] \n\t"
: [c] "=rm" (c)
: [a] "rm" (a), [b] "rm" (b)
: "eax", "ebx", "cc"
);
a
, but there is no such symbol. Because the variable a
is located on the stack and it really does not have a symbolic name. If it (together with b
and c
) were global, there would still be an error (at least when compiling for 64 bits), but different.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question