flat assembler
Message board for the users of flat assembler.

Index > Main > What are ALL the registers that I can use?

Author
Thread Post new topic Reply to topic
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
While reading the fasm documentation, I noticed there are a lot of registers, but fasm doesn't mention what are the functions of those.
Now usually I just use EAX, EBX, ECX, EDX, ESI, EDI, and EBP willy-nilly...

But wouldn't it be NICE if I can also use other registers?
Now I know usually CS, DS, SS should not be fooled around with,
but I'm not sure why though... I know in DOS, CS holds the segment of my instructions, DS is the default segment for my data, and SS is the segment for my stack. But what happens in 32bit mode? Doesn't everything go into one big segment? Or does windows grab those registers and use it for something else?

And what about ES, FS, GS? I vaguely remember someone mentioning that at a pinch, one can use FS and GS like a general register. Is it true?

There are also control registers, debug registers, test registers, floating registers, mmx registers, and SSE registers.

Do they all have specialised use, or can I use maybe one or two of them when I'm running out of registers?
Post 24 Sep 2005, 07:45
View user's profile Send private message Reply with quote
Redragon



Joined: 27 Nov 2004
Posts: 101
Location: U.S.
Redragon
Im no big asm programmer, but i was asking the same kinda question as this before, ive found all this while searching the net.. mabye this will help

[DATA REGISTERS - 32bit]

EAX - the accumulator
EBX - the base register
ECX - the counter register
EDX - the data register

[ADRESS REGISTERS - 32bit]

ESI - the source register
EDI - the destination register
ESP - the stack pointer register
EBP - the stack base pointer register

[CONTROL REGISTERS - 32bit]

CR0
CR1
CR2
CR3

[TEST REGISTERS - 32bit]

TR4
TR5
TR6
TR7

[DESCRIPTOR REGISTERS - 32bit]

GDTR - the global descriptor table register
LDTR - the local descriptor table register
IDTR - the interrupt descriptor table register

[SEGMENT REGISTERS - 16bit]

CS - code segment - points to the active code segment
DS - data segment - points to the active data segment
SS - stack segment - points to the active stack segment
ES - extra segment - points to the active extra segment

[POINTER REGISTERS - 16bit]

IP - instruction pointer - points to the offset of the next instruction
SP - stack pointer - points to the offset that the stack is using
BP - base pointer - used to pass data to and from the stack

[GENERAL PURPOSE REGISTERS - 16bit]

AX - accumulator register - mostly used for calculations & for input/output
BX - base register - only register that can be used as an index
CX - count register - register used for the loop instruction
DX - data register - input/output and used by multiply and divide

[INDEX REGISTERS - 16bit]

SI - source index - used by string operations as source
DI - destination index - used by string operations as destination

================================================

to answer your CS DS question, normally CS and DS are NOT used in 32bit programming, their used in 16bit (real mode)

and, in real mode you can NOT use AX,CX, or DX to hold an offset.

FS and GS are extra segment registers
Post 24 Sep 2005, 19:37
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
you may also occur name "MSW" - machine status word i think, which is lower 16 bits of CR0 (MSW was it's name on 286).
Post 25 Sep 2005, 09:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
register usage may depend on what os you are using: if you code under windows you should preserve ebx, esi and edi in your functions, called by winapi, and remember, that eax, edx and ecx can be destroyed while calling api functions: eax is used to return result, 64-bit result can be returned in edx/eax, ecx is often used as counter and just not restored.
Post 26 Sep 2005, 05:55
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
wht36: You are correct, you can use eax,ebx,ecx,edx,edi,esi and ebp "willy-nilly". Don't bother to use DS. CS, ES, FS, GS or SS in a protected OS unless you like to see general protection faults. Use R8-R15 "willy-nilly" if you have 64 bit. Use mmx0-mmx7 when you don't use ST(0)-ST(7) and vice-versa, use ST(0)-ST(7) when your not using mmx0-mmx7. Use XMM0-XMM7 whenever you feel like it and XMM8-XMM15 for 64 bit. CR?, TR?, ?DTR, MSR and MTTR probably are not going to be available to you for normal programming tasks.
Post 26 Sep 2005, 06:51
View user's profile Send private message Visit poster's website Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Thanks! Sigh, I guess I will continue fooling around with my old registers for now (back to push and pop, push and pop...).
Looks like the other registers is too special. Perhaps if my old computer finally breaks down, I will upgrade and use MMX... Wink
Still, it's a pity so many registers are special and not available for normal programming.
Post 26 Sep 2005, 16:03
View user's profile Send private message Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware
Welcome to the wonderful world of the Intel x86 family Smile
Post 26 Sep 2005, 17:28
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
jdawg



Joined: 26 Jun 2005
Posts: 39
jdawg
Depending on the current CPU privelege level you are allowed to use any registers you please. If you code to 16bit format, you can also increase the number of valid instructions you are allowed without switching levels. U should check out Intel, and AMD's sites, they have downloadable coverage of everthing you could ever want to know about the IA32/64 architechure, including system development. They cover every register available to you and what CPU models those registers are available on.
Post 03 Dec 2005, 09:17
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
Hmmm the debug registers are missed out
Post 03 Dec 2005, 12:29
View user's profile Send private message Visit poster's website MSN Messenger 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.

Powered by rwasa.