flat assembler
Message board for the users of flat assembler.

Index > Main > Is there some rules to use registers?

Author
Thread Post new topic Reply to topic
LiuJunfeng



Joined: 28 Nov 2003
Posts: 48
Location: China
LiuJunfeng
Which registers can be used freely and which must be saved before use?
Post 09 Apr 2004, 13:22
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
ebx esi edi ebp esp must be saved, rest u can use

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 09 Apr 2004, 14:05
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
this also goes for calls to external routines (like the win32 api) - you should always assume eax,ecx,edx are trashed, even if they aren't on your windows version.

Don't modify segment registers.

If you std, always cld before returning from a callback.

Always keep stack aligned to a 4-byte boundary, the same goes for various structures and such (not only is this better speedwise, you will get problems on NT with some APIs and some structures if they aren't 4byte aligned).

Can't think of any more things right now, but I'm sure there's a few more that will pop up.
Post 09 Apr 2004, 21:39
View user's profile Send private message Visit poster's website Reply with quote
LiuJunfeng



Joined: 28 Nov 2003
Posts: 48
Location: China
LiuJunfeng
Thank you a lot! That's a good start for me.
Post 10 Apr 2004, 07:50
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
A few things more from Agner Fog's (c) optimizations manual (pdf):
Quote:
4.5 Register usage in 32 bit Windows
[...] The interrupt flag cannot be cleared. The floating point
register stack is empty at the entry of a procedure and must be empty at return, except
for ST(0) if it is used for return value. MMX registers may be changed by the procedure
and if so cleared by EMMS before returning and before calling any other procedure that may
use floating-point registers. All XMM registers may be modified by procedures. Rules for
passing parameters and return values in XMM registers are described in Intel's application
note AP 589. A procedure can rely on EBX, ESI, EDI, EBP and all segment registers being
unchanged across a call to another procedure.

_________________
x86asm.net
Post 11 Apr 2004, 07:07
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.