CPU Registers x86-64
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
CPU Registers x86-64
Hi,
About a year ago, I created the CPU Registers x86 page. Since this page explains only 32-bit registers, someone (Roman) copied this page to form the CPU Registers x86-64 page, with just some additions. Still, many sections remained the same as in the original page. After a lot of time of inactivity, I finally added the notice about the factual inaccuracy of the CPU Registers x86-64 page. Since I have no experience with x86-64 yet, I'm unable to correct this page, so it would be nice if anyone with the relevant experience did it.
Regards,
glauxosdever
About a year ago, I created the CPU Registers x86 page. Since this page explains only 32-bit registers, someone (Roman) copied this page to form the CPU Registers x86-64 page, with just some additions. Still, many sections remained the same as in the original page. After a lot of time of inactivity, I finally added the notice about the factual inaccuracy of the CPU Registers x86-64 page. Since I have no experience with x86-64 yet, I'm unable to correct this page, so it would be nice if anyone with the relevant experience did it.
Regards,
glauxosdever
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Registers x86-64
Why did you separate the general purpose registers into "general purpose", "pointer", and "index" sections?glauxosdever wrote:About a year ago, I created the CPU Registers x86 page.
Re: CPU Registers x86-64
?
eax, ebx, ecx, edx are general purpose registers.
ebp, esp, eip are pointer registers.
esi, edi are index registers.
I don't see anything wrong there.
eax, ebx, ecx, edx are general purpose registers.
ebp, esp, eip are pointer registers.
esi, edi are index registers.
I don't see anything wrong there.
Every good solution is obvious once you've found it.
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Registers x86-64
EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI are general purpose registers. They can all be used interchangeably for all instructions that take explicit operands. Separating them implies that there is some difference in how they function, but they all work the same way.
Re: CPU Registers x86-64
I think that I would keep them separate.
It is true that they can all be used as operands, but there are plenty of instructions that specifically target some of these registers, like push, pop, cmps, enter, etc.
This pretty much dictates that you don't use, say, ESI and EDI for simple math, unless you have no other choice.
It is true that they can all be used as operands, but there are plenty of instructions that specifically target some of these registers, like push, pop, cmps, enter, etc.
This pretty much dictates that you don't use, say, ESI and EDI for simple math, unless you have no other choice.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Re: CPU Registers x86-64
For one thing, not all of them are byte-accessible/addressable (unless we're talking 64-bit mode with e.g. SIL, BPL).Octocontrabass wrote:EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI are general purpose registers. They can all be used interchangeably for all instructions that take explicit operands. Separating them implies that there is some difference in how they function, but they all work the same way.
For another, not all 16-bit regs can be used for memory accesses.
So, some generality is lost.
I'm being a little picky.
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Registers x86-64
Plenty of instructions specifically target EAX, and a few of those also target EDX. Why not put EAX and EDX in their own section?SpyderTL wrote:It is true that they can all be used as operands, but there are plenty of instructions that specifically target some of these registers, like push, pop, cmps, enter, etc.
That's when xchg comes in handy. However, the separation also exists on the page for 64-bit registers.alexfru wrote:For one thing, not all of them are byte-accessible/addressable (unless we're talking 64-bit mode with e.g. SIL, BPL).
The registers you can use for 16-bit addressing are SI, DI, BP, and... BX. The separation doesn't match this use case.alexfru wrote:For another, not all 16-bit regs can be used for memory accesses.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: CPU Registers x86-64
Wouldn't it be a better idea overall to merge the pages into one?
Re: CPU Registers x86-64
I think we can all agree to putting a single register in a "category" by itself is missing the whole point of "categories"... in the same way that putting all registers in one category labeled "general purpose" doesn't make sense.Octocontrabass wrote:Plenty of instructions specifically target EAX, and a few of those also target EDX. Why not put EAX and EDX in their own section?
We could argue that the osdev wiki has too many, or too few categories, but I don't see how putting everything in one category because they are all "articles", or having one category per article would help anyone. If your argument is that ESP is similar enough to EAX to put them in the same category, I can see your point. I just happen to disagree that, for someone just starting to learn about registers, putting them all together makes a whole lot of sense.
But it is a wiki. You can always change it if it makes more sense to you.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Re: CPU Registers x86-64
If you were new to assembly, I think putting all of the 16-bit, 32-bit and 64-bit registers on the same wiki page would be a little confusing. And we have plenty of users who are new to assembly...Combuster wrote:Wouldn't it be a better idea overall to merge the pages into one?
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: CPU Registers x86-64
Hi,
I think the way I had split the General Purpose Registers to Index and Pointer categories is at worst acceptable, at best it will help newbies understand the differences between them, as Solar, SpyderTL and alexfru have pointed out.
The issue is in the x86-64 page, which is anyway the cause for which I started this thread. I explained what is wrong with it in my first post.
By the way, is it possible that anyone with experience with other architectures documents registers that these architectures have?
Regards,
glauxosdever
I think the way I had split the General Purpose Registers to Index and Pointer categories is at worst acceptable, at best it will help newbies understand the differences between them, as Solar, SpyderTL and alexfru have pointed out.
The issue is in the x86-64 page, which is anyway the cause for which I started this thread. I explained what is wrong with it in my first post.
By the way, is it possible that anyone with experience with other architectures documents registers that these architectures have?
Regards,
glauxosdever
Re: CPU Registers x86-64
TBH I would go straight to the Intel manuals for this sort of information. I'm not sure that putting these details on a Wiki page is not counterproductive as it may discourage people from reading the manuals or a proper tutorial. I realize that the manuals are large, but this information is in the introductory chapter which, really, everyone should read.
I'm not in favour of oversimplification.
I'm not in favour of oversimplification.
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: CPU Registers x86-64
Hi,
I agree that is useful, if not mandatory, to read the Intel manuals when writing an operating system. On the other side, I think it's good to have a quick reference about registers, in the same way we have several pages about the different processor modes, the different structures used in these modes and many other things easily found in the Intel manuals.
Then there are even more pages about other hardware, filesystems, executable formats... All of these have their respective specifications, in the same way you can find the information about registers in the Intel manuals. So, why having a wiki in the first place, when everything (or almost everything) can be found in other places? (rhetorical question)
For the record, I added the CPU_Registers_x86 and CPU_Registers_x86-64 pages to a new category. I think these pages will be better organised this way.
Regards,
glauxosdever
I agree that is useful, if not mandatory, to read the Intel manuals when writing an operating system. On the other side, I think it's good to have a quick reference about registers, in the same way we have several pages about the different processor modes, the different structures used in these modes and many other things easily found in the Intel manuals.
Then there are even more pages about other hardware, filesystems, executable formats... All of these have their respective specifications, in the same way you can find the information about registers in the Intel manuals. So, why having a wiki in the first place, when everything (or almost everything) can be found in other places? (rhetorical question)
For the record, I added the CPU_Registers_x86 and CPU_Registers_x86-64 pages to a new category. I think these pages will be better organised this way.
Regards,
glauxosdever
Re: CPU Registers x86-64
Well, I'd say that the point of a technical Wiki like this is to record information not easily found elsewhere rather than just reproducing - or, worse, producing a precis of - official documentation. It can certainly be useful to expand on that documentation when it is rather sparse (although the Intel manuals could hardly be called sparse when it comes to describing the programmer's model of the processor). When the Wiki is liable to encourage people not to read the official documentation then I feel it is doing a disservice. Another use, of course, is to give information that is not easily found elsewhere; some technical documentation can be difficult to find - again, this can hardly be said of the Intel programmer's manuals.glauxosdever wrote:So, why having a wiki in the first place, when everything (or almost everything) can be found in other places? (rhetorical question)
We often see in these forums the results of people following minimal information; I think giving a crib sheet of the processor registers is minimal information which gives no real idea of how the processor works and how to program it. If you need to know it you will read the manual and very soon learn it; it's really not that complicated a piece of information. It's like giving a crib sheet of the controls in my Hyundai i30 - I don't need it as I use the thing every day. Just my opinion.
Now a page that gave brief comparative details of all the commonly met processors might be a lot more useful, helping people choose which processor looked interesting to them, but it would need to cover things like instruction sets and addressing modes rather than just listing registers.
Re: CPU Registers x86-64
There could be many categories. This type of relation is called many-to-many. And it can be very useful. Not always, of course, but sometime it can simplify person's understanding of an instruction or even some algorithm involving categorized register.SpyderTL wrote:I think we can all agree to putting a single register in a "category" by itself is missing the whole point of "categories"... in the same way that putting all registers in one category labeled "general purpose" doesn't make sense.
Human's way to remember things is about making a network of entities using brain's neurons. The wider/richer network is the better understanding the person has. Many categories could add to the richness. But it should be a useful richness and not just some space filling information. It is possible to give some historic perspective of the register evolution and show that there was just one register for arithmetic operations and it was caller accumulator (short form - A, it was "accumulating" some result value until it finally moved somewhere else - in memory or port address), it was just 4 bit wide. Next there was some progress and the need for another register arrives. Next with another progress step the width was extended to 8 bits and so on. So we had A, next B, next BL and BX, next EBX was added and finally the RBX arrived along with R8-15. But even today we still have the same accumulator register in the form of the RAX/EAX registers. Today there are many registers, but the history (or the legacy?) plays it hard and insists on using the RAX/EAX for some operations. So, the "accumulator category" is alive and sound even today.
We can see something similar with the index registers, with pointer registers and with other "general purpose" registers. And from the other side we can use registers like ESP for calculations or as a temporary storage while treating it as a really general purpose thing. The only problem with it - it's too complex and error prone to use it in such a way. But the situation is different with another pointer register - the EBP. It can be used perfectly as a plain general purpose register with some minor exclusions. And only historical legacy of function call implementation remembers us about the role of the EBP. Would there be no legacy code there will be no need for EBP's special role (and it's the case for "legacy free" implementations of OSes).
So, I just think it's very useful to get the idea of why some registers exist and why they are the way they really are. But one note should be mandatory - it's about Intel's legacy. Other processors can have their own exciting history with special registers and many interesting design decisions.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability