This post explains how two states, 0 and 1, become the memory that the operating system manages. Students learn binary in Unit 3, logic gates in Unit 4, memory in Unit 2 and memory management in Unit 5. These lessons are one chain, and each link uses the link before it.
The post has five parts:
- The whole chain: the eight links in one picture (section 1).
- How bits are added: two states and binary addition, the logic gates for one column, the half adder and the full adder (sections 2 to 5).
- How bits are kept: combinational and sequential circuits, the flip-flop and the register (sections 6 to 8).
- Where the chain is used: the memory hierarchy and the operating system (sections 9 and 10).
- How the exam tests it: past paper questions on the chain (section 11).
1. The chain in one picture
The chain has eight links, from two states to the memory work of the operating system.
Read the chain from step 1 to step 8:
- A computer uses two states, 0 and 1 (3.1).
- With two states, we can do binary addition. Each column gives a sum and a carry (3.3).
- Logic gates follow rules for bits. Some gates follow the same rules as binary addition (4.1).
- A half adder and a full adder are gates that add (4.4).
- A flip-flop is gates that remember one bit (4.4).
- A register is a row of flip-flops (2.3).
- The memory hierarchy starts with registers and ends with secondary storage (2.4).
- The operating system manages this memory (5.3, 5.4).
The syllabus itself joins steps 4 and 5 to memory. Its title is "Explores how combinational Logic circuits are used in CPU and sequential circuits in physical memory" (Syllabus 4.4, pages 13 and 14) (විෂය නිර්දේශය 4.4, පිටුව 13). Memory management lists "Physical Memory" again (Syllabus 5.4, page 17) (විෂය නිර්දේශය 5.4, පිටුව 16). The Sinhala syllabus calls it "භෞතික මතකය".
The Sinhala title of level 4.4 is not clear. It reads "මධ්ය සැකසුම් ඒකකයෙහි සහ භෞතික මතකයෙහි (physical memory) ඇති අනුක්රමික පරිපථයන්හි (sequential circuits), ඒකාබද්ධ තාර්කික පරිපථ භාවිත කරන ආකාරය ගවේෂණය කරයි" (විෂය නිර්දේශය 4.4, පිටුව 13). This sentence says that combinational logic circuits are used in the sequential circuits of both the CPU and physical memory. The English title splits them: combinational circuits in the CPU, sequential circuits in physical memory. Use the English reading. The Sinhala title also calls combinational circuits "ඒකාබද්ධ තාර්කික පරිපථ", but the Sinhala Teachers' Guide calls them "සංයෝජන පරිපථ" (section 6).
2. Two states and binary addition
A computer uses two states, and binary addition of two bits gives two outputs, a sum and a carry.
A computer works with electricity. The Teachers' Guide says that its functions are controlled by two states, power ON and power OFF (Teachers' Guide 3.1, page 75) (ගුරු අත්පොත 3.1, පිටුව 83). The Sinhala Guide calls them "ද්වී තත්ත්ව" and says that they are two different voltage levels ("එකිනෙකට වෙනස් වූ වෝල්ටීයතා මට්ටම් දෙකකි"). We write these two states as 1 and 0. Thus, the computer uses the binary number system.
Add 1011 and 0110 by hand. Both Teachers' Guides use this example (Teachers' Guide 4.4, page 119) (ගුරු අත්පොත 4.4, පිටුව 130). Start from the right. In each column, add two bits and the carry from the column before. Each column gives two outputs:
- a sum bit, which stays in that column,
- a carry bit, which goes to the next column on the left.
For example, 1 + 1 = 10 in binary. The sum is 0 and the carry is 1 (Teachers' Guide 4.4, page 118) (ගුරු අත්පොත 4.4, පිටුව 129).
Remember these two words, sum and carry. They come back in every section of this post.
The number of inputs also matters. Two inputs give 2² = 4 combinations. Three inputs give 2³ = 8 combinations (Teachers' Guide 4.1, page 91) (ගුරු අත්පොත 4.1, පිටුව 101). A column with a carry in has three inputs, so its truth table has 8 rows.
3. Logic gates for one column
The sum of one column follows the XOR rule, and the carry follows the AND rule.
Look at only one column with two bits, A and B. Write all four combinations and the sum and carry for each. This is the truth table of one-bit addition (Teachers' Guide 4.4, page 118) (ගුරු අත්පොත 4.4, පිටුව 129).
Compare the two output columns with the logic gates (4.1):
- The Sum column is 1 when A and B are different. That is the rule of the XOR gate.
- The Carry column is 1 only when A and B are both 1. That is the rule of the AND gate.
This is the key step in the chain. Binary arithmetic (Unit 3) and logic gates (Unit 4) are not two different ideas. Addition of bits is a set of logic rules.
The bitwise operations (3.3) show the same thing. A bitwise XOR applies the XOR rule to each pair of bits (Teachers' Guide 3.3, page 89) (ගුරු අත්පොත 3.3, පිටුව 97). The Sinhala Guide calls it "බිටු අනුසාරිත XOR මෙහෙයුම".
4. The half adder
A half adder is an XOR gate and an AND gate with the same two inputs.
Put the two gates from section 3 side by side. Give them the same inputs, A and B. The result is a half adder. The Sinhala Guide calls it "අර්ධ ආකලකය" (ගුරු අත්පොත 4.4, පිටුව 129).
- Sum = A XOR B
- Carry = A . B
The Teachers' Guide says that a half adder lets us make circuits that do simple addition with logic gates (Teachers' Guide 4.4, page 118) (ගුරු අත්පොත 4.4, පිටුව 129). The Sinhala Guide calls the sum "එකතුව(SUM)" and the carry "ඉදිරියට ගෙනයන (carry-out) බිටුව".
A half adder has two inputs and two outputs. It has no carry in. Thus, it can add only the first (rightmost) column, where no carry comes in (Teachers' Guide 4.4, page 119) (ගුරු අත්පොත 4.4, පිටුව 130).
5. The full adder and many bits
A full adder adds three bits, and a row of full adders adds numbers of many bits.
Every other column has three inputs: A, B and the carry in. For these columns, we need a full adder. It has three inputs and two outputs (Teachers' Guide 4.4, page 118) (ගුරු අත්පොත 4.4, පිටුව 129). The Sinhala Guide calls it "පූර්ණ ආකලකය" and the carry in "ඉදිරියට ගෙන එන (carry-In) අමතර බිටුව".
The full adder gives:
- Sum = A XOR B XOR C
- Carry out = A.B + B.C + A.C
Here C is the carry in (Teachers' Guide 4.4, page 119) (ගුරු අත්පොත 4.4, පිටුව 130).
A full adder can be built from two half adders. The first half adder adds A and B. The second half adder adds that sum and the carry in. An OR gate joins the two carry outputs. The Sinhala Teachers' Guide does not show this method.
Now join full adders in a row. The carry out of each adder goes into the carry in of the next adder on the left. The Teachers' Guide says that eight full adders in a row give an 8-bit adder (Teachers' Guide 4.4, page 118). The Sinhala Teachers' Guide does not have this sentence. This is the adder in the ALU of the CPU. The syllabus calls it a "building block of CPU" (4.4). The Sinhala syllabus calls these "මධ්ය සැකසුම් ඒකකයේ තැනුම් ඒකක" (විෂය නිර්දේශය 4.4, පිටුව 13).
6. Combinational or sequential
A combinational circuit forgets, and a sequential circuit keeps its last state with a feedback loop.
The adder has one big limit. It does not remember anything. When the inputs change, the old result is lost.
The Teachers' Guide gives two types of circuits (Teachers' Guide 4.4, page 120) (ගුරු අත්පොත 4.4, පිටුව 131):
- Combinational circuit. The output depends only on the inputs at that time. Half adders and full adders are combinational. The Sinhala Guide calls it "සංයෝජන පරිපථ".
- Sequential circuit. The output depends on the present inputs and also on the previous inputs and outputs. The Teachers' Guide says that this type is used for memory storage (SRAM). The Sinhala Guide calls it "අනුක්රමික පරිපථ" and says "SRAMහි භාවිත වන්නේ මෙම ක්රමවේදය වේ".
Gates remember when the output goes back into the input. This is a feedback loop (4.4). The Sinhala syllabus calls it "ප්රතිපෝෂණ ලූපය (Feed Back Loop)" (විෂය නිර්දේශය 4.4, පිටුව 13). With a feedback loop, the circuit can keep its last state.
7. The flip-flop keeps one bit
A flip-flop is a sequential circuit that keeps one bit.
A flip-flop is made from logic gates. The Teachers' Guide says that flip-flops "can also be considered as the most basic idea of a Random-Access Memory" (Teachers' Guide 4.4, page 120) (ගුරු අත්පොත 4.4, පිටුව 131). The Sinhala Guide calls it "පිළි-පොළ" and a temporary memory ("තාවකාලික මතකයක්"), and writes "සසම්භාවී ප්රවේශ මතකයෙහි සරල ම අවස්ථාව පිළි-පොළ ලෙස සැලකිය හැකි ය".
The simplest type is the RS (Reset Set) flip-flop. It has two inputs, Set and Reset. It has two outputs, Q and Q bar. Q bar is always the inverse of Q (Teachers' Guide 4.4, page 120) (ගුරු අත්පොත 4.4, පිටුව 131). The Sinhala Guide calls it "අගුළු පිළි පොළ (Latch Flip-flop)" and calls the inverse "ප්රතිලෝමය". It is made with two NOR gates or two NAND gates. The output of each gate goes into the other gate (Teachers' Guide 4.4, page 121) (ගුරු අත්පොත 4.4, පිටුව 131).
- Set puts the flip-flop in the state Q = 1.
- Reset puts the flip-flop in the state Q = 0.
- When both inputs go back to inactive, the flip-flop holds its last state. The Teachers' Guide says that the outputs "remain in this state until a similar pulse is applied to the other input" (Teachers' Guide 4.4, page 120) (ගුරු අත්පොත 4.4, පිටුව 131). The Sinhala Guide writes "අනික් ආදාන අග්රයට පෙර ආදාන අග්රයට ම ලබා දුන් අගය ලබා දෙන තෙක් ප්රතිදාන අගය එලෙස ම පවතී".
The hold state is the memory. One flip-flop keeps one bit.
The Sinhala Guide has an error on page 131. After the two outputs, it says "මෙම ප්රතිදාන ද්විත්වය Set and Reset input ලෙස හඳුන්වයි", which calls the output pair the Set and Reset inputs. Set and Reset are the two inputs. Q and Q bar are the two outputs.
The figure for the NAND flip-flop labels the inputs S and R with no further note (Teachers' Guide 4.4, page 121) (ගුරු අත්පොත 4.4, පිටුව 131). In a NAND flip-flop, an input is active when it is 0, not 1. Neither book says this. When a question uses NAND gates, trace the gates. Do not use the NOR rules.
8. Registers are rows of flip-flops
A register is a row of flip-flops that keeps a binary number.
One flip-flop keeps one bit. Many flip-flops in a row keep a binary number. This row is a register.
The Teachers' Guide says that a CPU register is a small data holding place in the processor. It "may hold an instruction, a storage address, or any kind of data" (Teachers' Guide 2.3, page 67) (ගුරු අත්පොත 2.3, පිටුව 72). The Sinhala Guide calls registers "මතක රෙජිස්තර". Its list names a memory address or any kind of data, and does not name an instruction. The syllabus lists "Memory (Registers)" as a part of the CPU (Syllabus 2.3, page 8) (විෂය නිර්දේශය 2.3, පිටුව 9). The Sinhala syllabus writes "මතකය (රෙජිස්තර)".
Here the two halves of the chain meet:
- Two registers (flip-flops) hold the two numbers.
- The adder in the ALU (full adders) adds them.
- The result goes into another register (flip-flops).
Adders compute. Flip-flops remember. A CPU needs both. The bitwise XOR (3.3) also works on registers: it can toggle selected bits in a register (Teachers' Guide 3.3, page 89). The Sinhala Teachers' Guide does not have this use of XOR.
9. Flip-flops in the memory hierarchy
The memory hierarchy starts at the registers, and the flip-flop explains why the top levels are volatile.
- Registers are flip-flops in the CPU. They are the fastest memory (2.4).
- SRAM keeps its bits as long as power is supplied. The Teachers' Guide says it is used for cache memory and register memory (Teachers' Guide 2.4, page 71) (ගුරු අත්පොත 2.4, පිටුව 78). The Sinhala Guide calls cache memory "වාරක මතකය". SRAM cells use the same feedback idea as a flip-flop. (This last point is reasoning, not a quotation.)
- DRAM must be refreshed continuously, or it loses its contents (Teachers' Guide 2.4, page 71) (ගුරු අත්පොත 2.4, පිටුව 78). It keeps bits in a different way, with capacitors. The Sinhala Guide calls the capacitor "ධාරිත්රකය" and the refresh "නැවුම් කළ (Refresh)". Thus, DRAM is cheaper and denser, but slower than SRAM.
- Secondary storage keeps data with magnetic, optical or flash technology (Teachers' Guide 2.4, page 72) (ගුරු අත්පොත 2.4, පිටු 78 සහ 79). The Sinhala Guide calls it "ද්විතීයක ආචයනය" and calls flash storage "ඝන තත්ත්ව ආචයනය (Solid state storage)".
A flip-flop needs power to keep its feedback loop. When the power goes off, the bit is lost. This is why registers, cache and RAM are volatile (Teachers' Guide 2.4, page 70) (ගුරු අත්පොත 2.4, පිටුව 77). The Sinhala Guide calls volatile memory "නශ්ය මතකය". The chain explains the definition, so students do not need to memorize it.
10. How the chain supports Operating Systems
Three topics in process and memory management (5.3, 5.4) use the chain directly: the context switch, the MMU and paging.
Context switch saves the registers
A context switch copies the registers of one process into memory. The Process Control Block (PCB) keeps the CPU registers of a process (Teachers' Guide 5.3, page 136) (ගුරු අත්පොත 5.3, පිටුව 147). The Sinhala Guide calls the PCB "ක්රියායන පාලන ඛණ්ඩය" and the CPU registers "ක්රියායන රෙජිස්තර". During a context switch, the context switcher "saves the content of all processor registers" of the old process in its PCB (Teachers' Guide 5.3, page 137) (ගුරු අත්පොත 5.3, පිටුව 148). The Sinhala Guide calls the context switch "සන්දර්භ ස්විචය". It says that the state of the process is recorded in its PCB and the process's data is removed from the registers.
The registers are flip-flops. Only one process can use them at a time. So the OS copies their bits into main memory, then loads the bits of the next process. The Teachers' Guide also says that context switch time is pure overhead, because modern computers have many registers to save (Teachers' Guide 5.3, page 137) (ගුරු අත්පොත 5.3, පිටුව 148). The Sinhala Guide calls this time an extra cost that makes the computer less efficient, and does not give the reason about many registers. The chain gives the reason: every register is a row of flip-flops to copy.
The MMU adds a register to an address
The Memory Management Unit (MMU) maps virtual addresses to physical addresses. The Teachers' Guide says: "The value in the base register is added to every address generated by a user process" (Teachers' Guide 5.4, page 141) (ගුරු අත්පොත 5.4, පිටුව 152). Its example: base register 10000 plus address 100 gives location 10100. The Sinhala Guide calls the MMU "මතක කළමනාකරණ ඒකකය" and the base register "මූලික (base) රෙජිස්තරය", and gives the same example.
Look at the words. A register (flip-flops) holds the base value. It is added (an adder) to the address. The MMU uses both halves of the chain.
Paging splits a binary address
In paging, physical memory is divided into frames, and the frame size is a power of 2, between 512 bytes and 8192 bytes (Teachers' Guide 5.4, page 141) (ගුරු අත්පොත 5.4, පිටුව 153). The Sinhala Guide calls paging "පිටුකරණය" and a frame "රාමුව". Because the size is a power of 2, a binary address splits cleanly into two parts:
- the high bits give the page number,
- the low bits give the offset inside the page.
A page table translates the logical address to a physical address (Teachers' Guide 5.4, page 141) (ගුරු අත්පොත 5.4, පිටුව 153). The Sinhala Guide calls it "පිටු වගුව". Questions on page tables, frame counts and address mapping are number system questions (3.1) in an OS context.
11. Past paper questions on the chain
The examiners already join these lessons. In 2023 (held 2024) Paper II, B, Q10, one question asks about registers made of flip-flops, the context switch and virtual memory with paging.
Adders and flip-flops (4.4) appear in 5 of the 8 new-syllabus papers, with 4 MCQs and 9 Paper II marks in total. Memory management (5.4) appears in all 8, with 33 Paper II marks. The 2023 (held 2024) paper has no official scheme, so its marks are estimates.
Try these questions. The answers are not in this post. Use the section in brackets to check the thinking.
- 2019 Paper I, Q37 and Q38: a logic circuit with sum and carry outputs (sections 4 and 5).
- 2024 Paper II, B, Q5(d): half adder, flip-flop as a memory element, full adder truth table (sections 4 to 7).
- 2020 Paper I, Q10: a block diagram of a sequential circuit (section 6).
- 2023 (held 2024) Paper II, B, Q5(c): the output Q of a NOR flip-flop as S and R change (section 7).
- 2025 Paper I, Q13: a NOR flip-flop with inputs i1 and i2 (section 7, and trace the gates).
- 2023 (held 2024) Paper II, B, Q10(a): the fetch-execute cycle, the context switch and registers made of flip-flops (sections 8 and 10).
- 2025 Paper I, Q7 and Q12: what registers hold, and signed addition in 8-bit registers (sections 2 and 8).
- 2020 Paper I, Q2 and 2021 (held 2022) Paper I, Q3: volatile memory and the memory hierarchy (section 9).
- 2020 Paper II, A, Q4(a): the PCB at a context switch (section 10).
- 2023 (held 2024) Paper II, B, Q10(e) and 2024 Paper II, B, Q10(d): virtual memory and frames (section 10).
- 2025 Paper II, A, Q4(b): swapping, address mapping and page faults (section 10).
