Message board for the users of flat assembler.
> Main > What are ALL the registers that I can use?
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?
|24 Sep 2005, 07:45||
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]
[TEST REGISTERS - 32bit]
[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
|24 Sep 2005, 19:37||
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).
|25 Sep 2005, 09:10||
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.
|26 Sep 2005, 05:55||
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.
|26 Sep 2005, 06:51||
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...
Still, it's a pity so many registers are special and not available for normal programming.
|26 Sep 2005, 16:03||
Welcome to the wonderful world of the Intel x86 family
|26 Sep 2005, 17:28||
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.
|03 Dec 2005, 09:17||
Hmmm the debug registers are missed out
|03 Dec 2005, 12:29||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.