Reputation: 61
Hope someone can help me out with this. I never learned ASM so I can't do anything with this snippet. But I need it for processing and it worked fine for me (was part of a code snippet i used for VC++ programming earlier, now I'm on Xcode 4.5), so I don't know how it exactly works.
I read on some posts, that I have to set quotes. BUT: Where?
asm(
fld newVal
fabs
fcom oldMax
fstsw ax
sahf
jna else_
fstp oldMax; // |newVal| > oldMax; pop to oldMax
jmp endif_
else_:
ffree st(0)
endif_:
);
I tried quotes on every line, on beginning and ending. Don't work.
Upvotes: 1
Views: 620
Reputation: 4713
asm
is the Visual Studio syntax, GCC and Clang use __asm__
for assembly language. Your code also appears to be in Intel syntax, GCC usually uses a slightly different syntax called AT&T. You can find out more at the GCC ASM how to.
Something like this would be a good place to get started:
__asm__(
"fld %0\n"
"fabs\n"
"fcom %1\n"
"fstsw %%ax\n"
"sahf\n"
"jna 1f\n"
"fstp %1 ; |newVal| > oldMax; pop to oldMax\n"
"jmp 2f\n"
"1:\n"
"ffree %%st0\n"
"2:\n"
: "=r"(newVal)
: "r"(oldMax)
: "%st0"
);
Upvotes: 2