There are three main memory models. In 64 bit linux, you use the new modern one, but it’s important to understand the other two even though they are now obsolete.
Before covering them though, there is some background info necessary.
Real mode flat model is like a smaller version of the modern model which is the protected mode. So master that one.
The sort of OG Intel processor was the 8080. 8-bit CPU, but had 16 address lines, so you could address 64KB. You put 16 bits out on address lines, you get 8 bits of data back which was stored at that address. Important to keep in mind that address bus and data bus not necessarily related, the hardware designer chooses.
The OS originally sat at the top of installed memory and loaded programs in at the bottom at address 0x0100. Each program would have to work and be loaded in 64KB(due to 16 bit addresses). When the 8086 came out, Intel wanted to make programs from the 8080 easy to port over to the 8086 even though the 8086 could address 1MB(since it had 20 address lines). This was done using segment registers which were pointers held in registers that pointed to a place in the MB of memory where tings begin. The segment registers would point to data storage, code execution, or whatever you wanted really. This was good for porting, but made things really annoying for new people that didn’t care and just wanted to use the whole 1MB without segments...
Unfortunately this means that segment registers still exist since we must maintain backwards compatibility. For pentium and newer the processor actually enters a virtual mode where it simulates and becomes an 8086 aka virtual 86 mode.
In the real world, a segment is a region of memory that begins on a 16byte aligned boundary. It then can but does not necessarily extend for 64KB. This boundary is called a segment address, which is the beginning of a segment.
The 8086 had 16 bit registers, but 20 address lines. How do you get a 20 bit address from a 16 bit register? You don’t. Instead, you use two. All memory locations in the MB of memory are assumed to reside in a segment. A byte’s complete address consists of the address of that segment along with the distance of the byte from the start of that segment. The segment address comes first, and the byte address comes second. Note that, with 64KB segments on 1MB of memory, you get 2^16 segment addresses. And in each segment, you get 2^16 locations. So, one 16 bit register handles the segment start, and one 16bit register handles the offset into that segment. Thus, the address of a byte was written as SegmentAddress:ByteOffset.
Note that segments may overlap, so the same byte might have a bunch of different addresses.
With this in mind, each segment register gets a name that relates to what it’s supposed to be for.
CS: code segment, usually machine instructions go here DS: data segment, variables and some other data. SS: stack segment, contains stack portion of memory ES: extra segment, just a spare one FS and Gs: same thing, but exist on 386 and later
Nowadays though, segments are history because modern computers have 48 address lines, which is plenty for all RAM you could use.
In the modern 64 bit world, the general purpose registers fall into four classes:
The 8, 16, and 32 bit registers are actually names for regions inside the 64 bit general purpose registers.
There are 8 16 bit general purpose registers: ax, bx, cx, dx, bp, si, di, and sp.
Then they get extended to 32 bits with names eax, ebx, ecx, edx, bp, si, ebp, esi, edi, esp.
Those got extended to 64 bits with prefix R, so rax, rbx, rcx, rdx, rbp, rsi, etc.
There are also more registers now, r8 - r15. rax contains eax, ax, ah, and al. ah and al are high byte and low byte.
This naming convention only works for the named registers. R8 and above use suffixes B for byte, W for word, D for double word, etc.
Holds useful info as bit values with interpreted purposes.
CPUs have math units that are colocated on the same chip. They come iwth their own registers in x64. There are 128 bit registers in here for advanced math computations. Some even have 512 bits.
Goal is to become fluent in x64 before diving into the deep math stuff, although the deep math stuff is the fun part.
The real mode we want to use is 64 bit long mode.