← Previous lessonFree lesson 3 of 3 · lesson 3 of 21

Unlock all 21 lessons of Linux System ProgrammingFull course ₹40,000 · paid

Price & syllabus
Free lesson · 29 min · no payment

Memory Hierarchy, CPU Registers, Paging, TLB and BIOS

A free lesson from Skill-Lync's Linux System Programming course, on Grow by Skill-Lync · Last updated 16 Nov 2026 · Session: “Week 1 Session 3”

What will you learn in this free Linux System Programming lesson?

The instructor covers the memory hierarchy from registers and caches to disk and cloud, x86-64 general purpose, segment and flag registers, and why virtual memory is used. It works through a page table and MMU example with 4 KB pages, explains the TLB, and describes BIOS, UEFI and POST.

  • Memory hierarchy: registers, cache, RAM, disk
  • x86-64 registers and status flags
  • Page tables, MMU and the TLB
  • BIOS, UEFI and the boot process

What comes after lesson 3?

Later in Skill-Lync's Linux System Programming course (paid): lesson 4, Week 1 Session 4; lesson 5, Week 2 Session 1; lesson 6, Week 2 Session 2. The full course has 21 lessons (7 h 25 min of video); see the course overview or its price and syllabus.

Lesson transcript

Machine transcript of the lesson audio (lightly cleaned). Technical terms may contain errors; the video is the reference.

This is week one, session three. Welcome to memory management. So in this session, we are going to cover different types of memories, some more thing about CPU cache, then we'll be looking into the CPU registers and so on. There are different kinds of the memory which are there in the computer system. So it can be the CPU registers, then it can be the L1, L2, L3 cache. L1, L2 caches are SRAM while L3 cache is DRAM. Then we can have the physical memory, which we say RAM or the main memory. Then we have the hard disk or secondary memory or SSSD or SSD.

Then we can have the tertiary memory which is called the remote storage on cloud. So if we look from the top to bottom, we have CPU registers here. Then we have L1 cache here. Then we have L1 cache here. Then we have L2 cache. Then we have L3 cache. And then we have physical memory, which is nothing but the RAM. Then we have hard disk, which is we also say as a secondary memory. And then we have the cloud. If we draw arrow here, something like this. So in this case, we can see the speed increases, cost increases, while if you can think the size decreases, this is the graph.

Now where this memory is actually placed. So we can say this is a CPU. Then inside the CPU, we can have a ALU. Then we can have the CPU registers here. So this is basically the CPU register. And then we can have L1 cache here. Then we can have L2 cache here. And we'll have a L3 cache here. So caches are connected from the back side bus. So this is back side bus. Then we have a front side bus. Then we have a front side bus. We set a front side bus. And it actually connects to the north bridge.

So this is we have the north bridge. And this is we have the south bridge. From the north bridge, we have the memory bus connected. Right. On memory bus, we have some RAM slots. We have some RAM slots. Then from the north bridge only, we have our PCIe bus connected. On PCIe extended, we can have our GPUs. And we can have some other devices, maybe something as sound card. From the south bridge. From the south bridge, we will have our ROM connected. Then we'll have our hard disk. Or we can say a SATA drive connected.

And we will have from the south bridge our Ethernet also connected. And we can also have our USB hub connected. So in the memory, first we have the CPU registers. So the register stores value on the CPU. And hardware registers are actually outside the CPU. So there are two diagrams here. One is x86-64 while one is x86-32. So in the difference between them is the registers on x86-64 has the range extended. That is they have RAX, RBX, RCX registers while the 32-bit registers. So these are 64-bit registers while on x86-32 it's EAX, EBX. So these are 32-bit registers.

So like RAX, RBX, these are the general purpose registers as it's mentioned below. The types are RAX, RBX and RDI, RSI. So if we talk about RAX, it's a 64-bit register. We also say it as an accumulator. It can be read as a 32-bit EX register or 16-bit AX register. So if we see here, it can be read as a 32-bit EX or 16-bit AX or 8-bit AH and AL register. Then the RAX register is used for storing the intermediate sum or subtraction or divide within a function. The RAX register also stores the return value of a function.

And in case of a division operator, RAX register stores the quitant and RDX stores the remainder. The purpose of RBX register is like it's a memory pointer or a base register. Then we have the RSP which is the stack pointer which points to the head of the stack. RBP is the base pointer which points to the base of the stack as written in the diagram here. Then we have the AVX register which is here. So the AVX register is advanced vector extensions and it's a 64-byte register which is present inside the Intel and AMD CPUs.

Then EDI, RSI, RDX, RCX. These all registers actually stores first six arguments of the function. Like if we have six arguments, these registers stores the six arguments. If we have more than six arguments, then program stack is used to pass the additional argument to the function. So RDI basically stores the first argument, then RSI stores the second, RDX stores the third, RCX stores the fourth, R8 then we have R8 which stores the fifth and R9 stores the sixth. So this is how the registers are. So this is we discussed that the CPU registers, general purpose registers like RF, RBX, RCX, these are general purpose registers used for the logical and address calculation and for temporary storage.

Now CPU has some segment registers which holds the segment addresses. So segment register initialization and management is normally handled by the operating system only. So there are majorly five types of registers. First is the CS which is the code segment. It contains address of code segment of currently executing instruction. Then we have the data segment. Then we have the data segment. Then we have the stack segment. So data segment DS register contains address of data segment which belongs to current program. Stack segment stores the memory address inside stack that CPU is using at this point of time. ES is the extra segment. It's a spare segment that may be used for specifying a location in a memory.

Then we have FS and GS. Then we have FS and GS. They are both additional segments with no specific job or speciality. So we will look at these code segment, data segment, stack and heap in the later weeks. So the CPU special purpose registers are the instruction pointer. We say instruction pointer. The other name of instruction pointer is program counter and on 64 bits operating system it's RIP and 32 bits EIP. It holds the offset address of next machine instruction to be executed in the current code segment. So if we are on a specific instruction on a specific line instruction pointer will hold the next instruction in the memory address that needs to be executed.

So IP can either read from or not be written directly by the user. So it's blocked from the user. Another special purpose register is program status word PSW. It's a 16 bit register. It tells about the status of the processor. So the usage is it contains bits which stores status or result of an operation. For example, bits of a program status word tells the sign of the previous operation. For example, whether the previous operation produced negative, positive or zero result. So it can contain the sign.

Then we have the status flags. So status flags are set or reset depending on the result of some of the arithmetic or the logical operations. So on the status flag, we have a CF. that is we have a carry flag. This is set if there is a carry out bit of a MSB position like from resulting from an addition operation or a subtraction operation. Like if there is a carry, this is set. Then we have an auxiliary flag here. So auxiliary carry flag. second as a third .

This is set if the carryout of bit 3 resulting from an additional addition operation. So, if we have, let's suppose, 1, 1, 1, something like this. So, 1 and 1 becomes 0 and it generates 1 here. So, it will be going to carry flag. And if 1, 1, 1, so it will have 1 and 1 here. So, this is again a carry operation. So, it will be going to an auxiliary carry flag. Then we have the third type of the register. Status flag is SF, that is sine flag, which is set when the result is negative.

And if result is positive, it's only 0. Then we have the 0 flag. So, it's set to 1 when the result of arithmetic or logical operation is 0. Then we have the PF, that is the parity flag. This is set to 1 when even number of 1 bits are in the result. So, if the result is something like this, right? So, in this case, the parity flag will be 1. And then we have the overflow flag, which is set if there is a signed overflow. So, if on an 8-bit memory, so we have, let's suppose, an 8-bit memory, which is something like 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8.

And we add 1 here, so it will generate overflow. So, in that case, this overflow flag will be set. There is one more CPU register called XMM register, which support 32 and 64-bit floating point operations. So, these are especially for floating point. Then, single instruction, multiple data, SMID instructions are also performed on XMM register. So, SMID instruction allows single instruction to be applied simultaneously to multiple data items. So, this basically, with this operation, that is, if we apply a single instruction to multiple data items, it results in performance improvement.

So, now, the difference between L1 and the L2 cache. So, if we remember earlier from the diagram that L1 cache is on the CPU box or on the CPU itself, while L2 cache and L3 cache are connected from the backside bus. So, L1 cache is always inside the CPU, while L2 cache have some XMB of memory data. Then, L1 cache holds the decoded instructions of a CPU, and L1 cache size is 16KB each, while there is no access delay. But since L2 cache is on a backside bus, outside the CPU chip, so the access delay is between 1 to 2 clock cycles.

So, if you want your application to be on a high speed, you want to execute it at the highest speed, then it should use L1 cache. In memory management, there is an important concept of virtual and the physical memory. So, we will be understanding the concept on the 16-bit system. So, we can understand it, understand on the 64 or 32-bit system, but understanding on the 16-bit system would be easier, and we can apply the same concept later. We will be looking onto the page table and translation look-aside buffer.

So, before moving on to these topics, let's see that why we need virtual memory. So, nowadays, our most of processes are RAM hungry. For example, Microsoft Teams, Adobe Photoshop, these need more RAM. And consider a situation if we have 10 such processes who want to run simultaneously on a 10GB RAM. We have 10 processes, and our system has only 10GB RAM, and then how it will execute? Like, one process will take 1GB of RAM, and if second process wants more than 1GB of RAM, then that will be a problem.

So, virtual memory is just an illusion to a program that it has complete access to RAM. So, if there is a virtual memory in our system, so all these 10 processes think that they have complete access to this 10GB RAM. So, let's see the sizes of the virtual memory. So, size of virtual memory, we can say a max virtual memory. If we have a hard disk of 4GB on a lower side, then we have the physical memory as 1GB, and the virtual memory as 3GB, and if I have a hard disk of 1GB, then we have the physical memory of 4GB, and virtual memory of 966GB.

If we look at, this is similar, same as the user space, or maybe the hard disk, which can be. So, hard disk basically is something like this, as we saw in earlier sessions. So, this part is used by the kernel, and this part is used by the user space. So, this complete user space part is the virtual memory, that is the illusion to the process. We will have the whiteboard demonstration. So, now we will be looking at the page table, translation look, aside buffer, and how conversion from virtual memory to physical memory takes place on a 16-bit system.

Let's consider we have a 16-bit system. It has 64 KB of hard disk, and it has somewhere 32 KB of RAM. Now, if we consider our page size as 4 KB, then this will be equal to 64 divided by 4, which comes out to be 16 pages of 4 KB each, and this will be 32 divided by 4, which will be 8 pages of 4 KB each. But in the real systems, page sizes will be bigger, somewhere around 64 KB. So, if we see what is a page table, a page table is a mapping table, which stores virtual page mapping to the physical pages.

So, if we consider our page table here, on one side, it will be having 16 pages, and on the other side, it will have smaller, 8 pages. So, this is our RAM, or we can say our physical memory, and this is our virtual memory. We say it as a hard disk, right? So, it will have 4 KB each page, while it will have only 8 pages, also the 4 KB size. So, if we start it from 0 here, so, this page will be 0 to 4 K, this will be 4 K to 8 K, then this will be 8 K to 12 K, and so on, it should be up to 64 K, while this will be from 0 to 4 K to 8 K, and it should go to 32 KB, right?

Since we have here. Now, this is our page table. So, how the page table is used? We are going to see it. So, suppose a program tries to access the virtual address 0. So, virtual address need to be mapped to the physical address. So, let's suppose the program says, I want physical address of the virtual address 0. So, 0 is a virtual address. This is sent to CPU. CPU says, get me the physical address of page 0 to MMU, and MMU will send the physical address of the virtual address is 8192, something here.

So, this means this is mapped to this here, okay? And this is used by the application. So, MMU has a map of all virtual addresses to all physical addresses. This is the memory management unit, right? So, similarly, if some other process asks that I want a physical address of the virtual address, CPU sends to MMU, the same address, 8192, and MMU returns back the physical address, something converted. Let's suppose 24K. So, 24K will be converted as 24 into 1024, which will be equal to somewhere 24,576, and this page is mapped somewhere here, something like this.

So, basically, paging, we can say, is process of dividing hard disk into equal size blocks. So, this is, this is the paging here. Then, we have, what we say, page is a block of memory on hard disk. So, this is a page, while on RAM, we say it a frame. So, in case of a page fault, CPU issues a trap and then goes and finds it, the mapping, and the MMU, memory management unit. Takes the virtual address as input, provides the physical address as output. That is, it does virtual to physical mapping. So there is an important piece which is the TLB, the translation look aside buffer. So where it is used. So TLB stands for translation look aside buffer. So now we will see what and why TLB is used.

So practically, from complete page table, only a fraction of page table entries are heavily used or heavily read. For example, if we consider 32-bit system. So a 32-bit system will have a bus size of 32-bit bus. That means at a time only 32-bits are sent. Maximum address which can be reached on a 32-bit bus is this one, 2 raised power 32, which comes somewhere around 32, which comes somewhere around 4294, 967296. Similarly for a 64-bit system, we will have a 64-bit bus and we access the maximum address as somewhere 18 into 10 is to power 18, which is equal to 18 exabytes. So the problem with 32 and 64-bit systems is, problem is, they have huge virtual tables. So if we see, we have a mapping from physical to the virtual memory. And if the page table gets, size gets big, if we consider the 32-bit case, the page save table will contain somewhere as 496, this number divided by 496.

4K, which comes out to be 4096. And that will be somewhere around 1 million entries. So 1 million entries are huge. And to search the data inside, the 1 million entries takes time. And even for the 64-bit system, this becomes more bigger. So the solution to this huge page table size is the TLB. So what TLB does is, so inside the MMU, there is a separate hardware called the TLB. This is MMU, which does the mapping from virtual to physical memory. So this hardware lies inside the MMU, which just stores few entries. So this TLB will only store 8 to 256 entries. That is very same to the page table, that is virtual address to the physical address mapping, but it stores very few.

So if a request comes to the TLB, then TLB, if the entry is found for this virtual address to the physical address, we say it at TLB hit. And if it is not found, we say it at TLB miss. So if it is a TLB miss, it will go to the page table as a normal process, finds the page table entry and updates the page table. So if there is no entry in the page table, the trap instruction will happen. And if there is an entry, then our TLB will be updated. Right? Update TLB.

So this is update TLB. Okay. The example format of a TLB is something like this. We will have entry something like this. The first entry would be valid, that whether this mapping is valid. Then we have the virtual page number. For example, we have 40. Then we have, is it modified? So it may be yes. Then we have the protection. Then we have the protection. So it may be read, right? And then finally, we'll have the page table or the frame number, which is the frame in the RAM. So it may be something as 32 or 31. Right? There are the problems in TLB. So the problem with TLB. So if you can just pause this video for a second and think what's the problem. So the problem with TLB is TLB is small.

So being small. So being small, it happens that process tries to get unused page every time. And there are a lot of TLB misses. So TLB uses, stores those pages, which are heavily read. So solution is software can maintain the cache internally. So now we are going to have a demo for dumping the physical memory using the machine address to the buffer. So the logic of this program is something like this. We have a machine address that is unsigned long, long, eight byte, which is there in MA. Then we'll take a void pointer, which points towards the local variable storing the machine address.

And then we'll typecast this machine address to the unsigned car. So here we have the function dumpToBuffer. And it will get the machine address written into this UN64. And this is the length 1024. In dumpToBuffer, we will allocate 1024 car, that is the memory of size 1024, 0 to 1024 or 1025. And then we go on to every buffer that is every memory location. And we will typecast the data and store back into this. So the program actually takes the machine address and then stores it inside the buffer.

And finally, slash 0 is inserted and back. So if we try to run this program, that returns this. So this is basically the machine address. In memory management, we have a concept of BIOS. BIOS stands for basic input output system, or we say ROM BIOS. So what is BIOS? This is a pre-installed firmware, software, which is used to perform hardware initialization during booting process, power on or startup. This is the first software that runs when the system is powered on. So we have heard about UEFI, which is mostly used in Linux. So UEFI stands for unified extensible firmware interface. This is successor to BIOS, which aims to address the technical problems, which are there in BIOS. The tasks which are performed by BIOS at power on. So it checks the CMOS for the setup.

So CMOS is like complimentary metal oxide semiconductor, which is a kind of chip which is used by BIOS to check the setup. Then it loads the interrupt handler and the device drivers. It initializes the registers and power management. BIOS also performs post that is power on self test. This tests the computer hardware ensuring the hardware is properly functioning before starting the process of loading the operating system. Then it displays the system settings while doing these things. Then it determines which devices are bootable. Initiates the bootloader. So bootloader loads the operating system.

So there are two kinds of BIOS. One is called the VBIOS and other is called the SMBIOS. So VBIOS is the video BIOS, which is the BIOS which is present on the GPU, GPU or the graphics card. So it initializes the GPU. It provides set of video related functions that are used by program to access the video hardware. SMBIOS eliminates need for operating system to probe hardware directly to discover what devices are present in the computer. So if we just look at the difference between the SMBIOS and BIOS. So BIOS is a firmware on the ROM chip, which is used for system boot, while SMBIOS is a data structure for reading the management information produced by BIOS.

So this is end of week one, session three. .

Want the rest of Linux System Programming?

Get the full course syllabus and fees.

The full course is paid (₹40,000). We'll send the syllabus and call you back within one working day.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Full course · paid

Unlock the full Linux System Programming course

The remaining 18 lessons, mentor-reviewed projects and a certificate come with the paid course (₹40,000). Leave your details: we'll send the syllabus and fees and call you back.

Get the syllabus and fees

A counsellor calls you back within one working day.

By submitting you agree to our Terms and Privacy Policy.

Grow by Skill-Lync · free lesson

Start watching

Free, no payment. Leave your details once and every free lesson on Grow plays straight away. A Skill-Lync counsellor may call you about the full Linux System Programming course.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.