Segment Registers in 64bit
Segment Registers in 64bit
Is there any reason that ES, FS, and GS cannot be used as a random place to store data in 64bit mode?
Programming is like fishing, you must be very patient if you want to succeed.
Re: Segment Registers in 64bit
Why just 64-bit mode? This would be even more useful in 32- or 16-bit modes, where you have less general-purpose registers available. But I believe that loading a segment register is a relatively expensive operation, so it may not be very efficient. And the fact that you can only write and read them makes them less useful.
You do already have an additional 8 general-purpose registers available in 64-bit mode.
You do already have an additional 8 general-purpose registers available in 64-bit mode.
Re: Segment Registers in 64bit
I was just thinking about using them as a place to cache parts of a register during certain operations. But the fact that there is still the overhead of them in 64bit mode was not something that I thought of and is a really good reason to not use them.
Programming is like fishing, you must be very patient if you want to succeed.
Re: Segment Registers in 64bit
I have thought this idea sometimes. If the global descriptor table contained duplicate entries, you could use the index value for storing data. It is not efficient but still one option. Untested example below.
Code: Select all
; Input: al = byte
PutByteRegisterDs:
shl ax, 8 ; ah = input byte
mov al, (DATA_SEGMENT) ; ax = segment selector
mov ds, ax
ret
; Output: al = byte
GetByteRegisterDs:
mov ax, ds ; ax = segment selector
shr ax, 8 ; al = return byte
ret