Subject: GNU assembly.
To: None <>
From: Richard Rauch <>
List: netbsd-users
Date: 08/10/2005 10:35:59
There is some i386-/amd64-specific stuff here, but it's not really one
or the other, and the general GNUish assembly rules is machine
independent, so...I wasn't sure where to post.  (It's also
not very NetBSD-specific, so the "general chatter" list of
netbsd-users seems good...  Maybe I'll try on port-i386 if I
don't get all of the answers I hope and dream for here on
netbsd-users.  (^&)

I was toying with a bit of code for WIN32 and Mac OS/X.  The OS/X
portion generally compiled with a little work.

However, there's some assembly code in there (some for Power PC,
some for i386).  It's not necessary, as there's multiple paths,
one of which goes through fairly generic C++.  I decided to take
a stab at getting the i386 assembly to pass through GCC on the
AMD64.  (The i386 assembly already there was for MSVC.)

I've done assembly on a few processors, but have been happily away
from it for a few years, and never did any floating point assembly

Okay, that's enough background.

Here are some questions that I have:

1) Is it true that GCC's asm() directive reverses operands,
relative to MSVC's asm{}?  (I.e., is GCC's asm() always
<source>,<dest> for two params, while MSVC is (I think)
standard Intel <dest>,<source>)?)

2) SAHF is undefined for the AMD64 (at least GCC doesn't
like it; a little googling suggests that this opcode may
have been supported in some AMD64 processors, but not others).
I only need the Carry flag, so I used "shr ah", which I think
will do the same thing.  Unless I have my Intel bits backwards.

3) My attempt to figure out what's happening with x87 FPU register
stack is presumably garbled.  I don't suppose anyone who knows
x87 FPU instructions would like to scan my attempt to work out
the register stack.

4) Related, GCC seems to use things ST(i) while an online
reference talks about STi.  I assume that these are just
different notation for the same FPU register stack, but
am not yet sure.

5) Finally, the MSVC asm{} code used the register ESI.
GCC didn't like that.  I guess that that was a 32-bit
register, which is probably why it didn't work on the AMD64.
I substituted %rsi on GCC's asm().  I *think* that that's
okay, but am not sure.

The code doesn't blow up, but doesn't do what it should.  (It's a
fractal drawing program.  When using vanilla C++ code, it works;
when using assembly, it essentially draws a blank window.)

Thanks in advance for any insight.

  "I probably don't know what I'm talking about."