<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>loga4m-log</title>
    <subtitle>Software Engineering Notes.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://loga4m.uz/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://loga4m.uz"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-03-09T00:00:00+00:00</updated>
    <id>https://loga4m.uz/atom.xml</id>
    <entry xml:lang="en">
        <title>Fix on system freezes due to GPU problem on ASUS ROG Strix G513M</title>
        <published>2026-03-09T00:00:00+00:00</published>
        <updated>2026-03-09T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              loga4m
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://loga4m.uz/gpu-fix/"/>
        <id>https://loga4m.uz/gpu-fix/</id>
        
        <content type="html" xml:base="https://loga4m.uz/gpu-fix/">&lt;h1 id=&quot;asus-rog-strix-g513rm-linux-freeze-gpu-fix&quot;&gt;ASUS ROG Strix G513RM — Linux Freeze &amp;amp; GPU Fix&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;hardware&quot;&gt;Hardware&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Model:&lt;&#x2F;strong&gt; ASUS ROG Strix G513RM&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CPU:&lt;&#x2F;strong&gt; AMD Ryzen (Rembrandt)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;GPUs:&lt;&#x2F;strong&gt; AMD Radeon 680M (iGPU) + NVIDIA RTX 3060 Mobile (dGPU)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;BIOS:&lt;&#x2F;strong&gt; G513RM.327 (latest available as of March 2026)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;problem&quot;&gt;Problem&lt;&#x2F;h2&gt;
&lt;p&gt;Persistent system freezes across multiple Linux distros. Root cause was the NVIDIA dGPU producing &lt;strong&gt;PCIe BadTLP errors&lt;&#x2F;strong&gt; (Bad Transaction Layer Packets) — corrupted communication between CPU and GPU over the PCIe bus, caused by PCIe ASPM power management dropping the link into an unstable state.&lt;&#x2F;p&gt;
&lt;p&gt;Secondary symptom: on warm reboot (not cold boot), the dGPU would disappear entirely from the PCIe bus (&lt;code&gt;lspci&lt;&#x2F;code&gt; returned nothing), requiring a full power cycle to recover.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;diagnosis&quot;&gt;Diagnosis&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;confirming-badtlp-errors&quot;&gt;Confirming BadTLP errors&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; dmesg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; badtlp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Output showed repeated:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nvidia 0000:01:00.0: PCIe Bus Error: severity=Correctable, type=Data Link Layer, (Receiver ID)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;nvidia 0000:01:00.0:  [ 6] BadTLP&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;confirming-gpu-presence&quot;&gt;Confirming GPU presence&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;lspci&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; nvidia&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Expected: 01:00.0 VGA compatible controller: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;fix&quot;&gt;Fix&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;step-1-enable-nvidia-dynamic-power-management&quot;&gt;Step 1: Enable NVIDIA Dynamic Power Management&lt;&#x2F;h3&gt;
&lt;p&gt;Create &lt;code&gt;&#x2F;etc&#x2F;modprobe.d&#x2F;nvidia.conf&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; nano &#x2F;etc&#x2F;modprobe.d&#x2F;nvidia.conf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Add:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;options nvidia NVreg_DynamicPowerManagement=0x02&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This allows the driver to properly manage GPU power state, preventing the PCIe link from going unstable.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;step-2-use-acpi-reboot-method&quot;&gt;Step 2: Use ACPI reboot method&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; nano &#x2F;etc&#x2F;default&#x2F;grub&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Change:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet splash reboot=acpi&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; update-grub&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This forces the kernel to use ACPI reboot instead of the default method, which properly resets PCIe device states on warm reboot.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;step-3-full-power-cycle-once&quot;&gt;Step 3: Full power cycle (once)&lt;&#x2F;h3&gt;
&lt;p&gt;After applying the above, do a full &lt;strong&gt;poweroff&lt;&#x2F;strong&gt; (not reboot), wait 10 seconds, then power on. This resets the EC (Embedded Controller) state.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; poweroff&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;verification&quot;&gt;Verification&lt;&#x2F;h2&gt;
&lt;p&gt;After cold boot:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# No output = no errors&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; dmesg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; badtlp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Should show GPU stats&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;nvidia-smi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Should show GPU on bus&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;lspci&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; grep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; nvidia&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;why-warm-reboot-loses-the-gpu&quot;&gt;Why warm reboot loses the GPU&lt;&#x2F;h3&gt;
&lt;p&gt;The ASUS ROG G513RM firmware (EC) does not properly restore dGPU power state on warm reboot — only on cold boot. The &lt;code&gt;reboot=acpi&lt;&#x2F;code&gt; parameter mitigates this in most cases. If the GPU still disappears after a warm reboot, a full power cycle (poweroff → wait → power on) always recovers it.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;kvm-conflicts-with-virtualbox&quot;&gt;KVM conflicts with VirtualBox&lt;&#x2F;h3&gt;
&lt;p&gt;KVM (&lt;code&gt;kvm_amd&lt;&#x2F;code&gt;) is loaded at boot. VirtualBox&#x27;s &lt;code&gt;vboxdrv&lt;&#x2F;code&gt; kernel module grabs a reference to KVM at load time, making it impossible to unload KVM while VirtualBox is installed. If running 64-bit VMs in VirtualBox fails with an i686 error, blacklist KVM:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F07178;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; &amp;quot;blacklist kvm_amd&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; tee &#x2F;etc&#x2F;modprobe.d&#x2F;blacklist-kvm.conf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F07178;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; &amp;quot;blacklist kvm&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt; sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; tee&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; &#x2F;etc&#x2F;modprobe.d&#x2F;blacklist-kvm.conf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; update-initramfs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -u&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; reboot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;wayland-nvidia&quot;&gt;Wayland + NVIDIA&lt;&#x2F;h3&gt;
&lt;p&gt;With the driver working correctly, GNOME Wayland session functions normally with the NVIDIA dGPU. Select &quot;Ubuntu on Wayland&quot; at the GDM login screen. Three-finger gestures and pinch-to-zoom work on Wayland; they do not work on X11.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;armoury-crate-control-service-update&quot;&gt;Armoury Crate Control Service update&lt;&#x2F;h3&gt;
&lt;p&gt;During troubleshooting, an update for Armoury Crate Control Service was applied via MyASUS on Windows. This service manages EC firmware and hardware control on ROG laptops. It may have patched EC behavior related to dGPU power state on warm reboot, and could be partially responsible for warm reboot stability alongside &lt;code&gt;reboot=acpi&lt;&#x2F;code&gt;. If warm reboot GPU loss recurs on a fresh install, check for Armoury Crate updates in Windows before assuming the Linux fix is insufficient.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-does-not-work&quot;&gt;What does NOT work&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Global &lt;code&gt;pcie_aspm=off&lt;&#x2F;code&gt; or &lt;code&gt;pcie_port_pm=off&lt;&#x2F;code&gt; kernel parameters cause the GPU to disappear from the PCIe bus entirely and require a full power cycle to recover. Do not use these.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;em&gt;Document was generated by Claude.ai&#x2F;Sonnet 4.6.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Essentials of Computer Architecture and Assembly</title>
        <published>2026-03-01T00:00:00+00:00</published>
        <updated>2026-03-01T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              loga4m
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://loga4m.uz/cp-arch-asm/"/>
        <id>https://loga4m.uz/cp-arch-asm/</id>
        
        <content type="html" xml:base="https://loga4m.uz/cp-arch-asm/"> &lt;!----&gt;


&lt;div
  class=&quot;my-4 flex flex-col rounded-lg bg-[var(--admonition-bg)]&quot;
  style=&quot;--admonition-bg: rgba(255, 145, 0, 0.1)&quot;
&gt;
  &lt;div class=&quot;flex items-center rounded-t-lg bg-[var(--admonition-bg)] p-1&quot;&gt;
    &lt;div
      class=&quot;mx-2 h-4 w-4 text-[0px] [background:var(--url)_center_center_no-repeat] dark:invert&quot;
      style=&quot;--url: url(.&#x2F;icons&#x2F;warning.svg)&quot;
    &gt;
      warning
    &lt;&#x2F;div&gt;
    &lt;span&gt;&lt;strong&gt;warning&lt;&#x2F;strong&gt;&lt;&#x2F;span&gt;
  &lt;&#x2F;div&gt;
  &lt;div class=&quot;pl-4&quot;&gt;&lt;p&gt;This article simplifies&#x2F;skips a lot of things. It is mainly intended to make
picking up assembly easier. Also, this is a write up of what I have
learned and understood over the course of reading CS:APP book and
doing some assembly exercises on &lt;strong&gt;Windows&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;&#x2F;strong&gt; This article is work in progress. I am filling the missing sections in my free time.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;&#x2F;h1&gt;
&lt;p&gt;This guide is a mix of topics from computer architecture,
operating systems, and assembly programming.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;cpu&quot;&gt;CPU&lt;&#x2F;h1&gt;
&lt;p&gt;The CPU, or &lt;em&gt;&lt;strong&gt;Central Processing Unit&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;, is a unit of computer hardware
that &lt;strong&gt;executes instructions&lt;&#x2F;strong&gt;. It is the &quot;brain&quot; of a computer system.&lt;&#x2F;p&gt;
&lt;p&gt;However,
it is not much clever as brain is. What it does is just to &lt;strong&gt;fetch&lt;&#x2F;strong&gt; next instruction, &lt;strong&gt;decode&lt;&#x2F;strong&gt; it,
and &lt;strong&gt;execute&lt;&#x2F;strong&gt; it. That&#x27;s it. This is called the &lt;em&gt;fetch-execute cycle&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In a simple model of single CPU which executes instructions &lt;em&gt;sequentially&lt;&#x2F;em&gt;, one at a time, the CPU
mainly consists of small memory, decoder, and Arithmetic Logic Unit (ALU).
It is also connected to an intermediary called &lt;strong&gt;System Bus&lt;&#x2F;strong&gt; which connects the CPU
to the other components in a computer hardware.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;strong&gt;ALU&lt;&#x2F;strong&gt; is the unit responsible for carrying operations like addition, subtraction,
multiplication, etc.&lt;&#x2F;p&gt;
&lt;p&gt;The memory of CPU, called &lt;strong&gt;register file&lt;&#x2F;strong&gt; (or just &lt;strong&gt;set&lt;&#x2F;strong&gt; of registers), is the
set of fastest memory elements in computer hardware which are used for storing operation results, intermediate results, addresses,
or any value that fits their capacity.&lt;&#x2F;p&gt;
&lt;p&gt;Analogously, if we say a CPU is a person solving a math problem, then register file
(the set of registers) is a collection of scratch papers.&lt;&#x2F;p&gt;
&lt;p&gt;Below is a simplified diagram.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;simple_cpu.png&quot; alt=&quot;Simplified CPU diagram&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;registers&quot;&gt;Registers&lt;&#x2F;h1&gt;
&lt;p&gt;We can talk a lot about registers.&lt;&#x2F;p&gt;
&lt;p&gt;So, what is a register? A register is a storage with a fixed capacity (in bits). It just stores
plain bits.&lt;&#x2F;p&gt;
&lt;p&gt;There are mainly two types of CPU registers: &lt;em&gt;General Purpose&lt;&#x2F;em&gt; and &lt;em&gt;Special Registers&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;General Purpose Registers&lt;&#x2F;em&gt; (GPRs) are those we are given access to, while &lt;em&gt;special registers&lt;&#x2F;em&gt;
are mostly limited to the usage by the CPU.&lt;&#x2F;p&gt;
&lt;p&gt;One important register is called &lt;strong&gt;Program Counter&lt;&#x2F;strong&gt; (or instruction pointer). It stores
the &lt;em&gt;address&lt;&#x2F;em&gt; of the next instruction.&lt;&#x2F;p&gt;
&lt;p&gt;In x86-64 systems, registers typically have capacity of 64 bits. Due to historical reasons, &lt;strong&gt;in terms
of access&lt;&#x2F;strong&gt;, they are &quot;divided&quot; into parts: lower 64-bit, lower 32-bit and lower 16-bit.&lt;&#x2F;p&gt;
&lt;p&gt;The lower 16-bit itself has upper and lower bytes. This means we can use the upper byte
or lower byte -- directly. In contrast, some GPRs &lt;strong&gt;do not have&lt;&#x2F;strong&gt; this support of directly
using the &lt;strong&gt;upper byte&lt;&#x2F;strong&gt; of lower 16-bit.&lt;&#x2F;p&gt;
&lt;p&gt;This division gives us the ability to access&#x2F;use the specified portions of registers.
In other words, we can directly access parts contained in the boxes (yes, boxes).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;register.png&quot; alt=&quot;Simplified register parts&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Why is this due to historical reasons? As registers had lower capacity than 64-bit in the &lt;em&gt;past&lt;&#x2F;em&gt;,
hardware manufacturers modernized the processors with &lt;strong&gt;backward-compatibility&lt;&#x2F;strong&gt; in mind
so that old programs could run on &lt;em&gt;newer processors&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Note, this &quot;division&quot; is crucial -- since we quite often use them in assembly.&lt;&#x2F;p&gt;
&lt;p&gt;Below is a diagram presenting some of registers in x64 (&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;cs.brown.edu&#x2F;courses&#x2F;cs033&#x2F;docs&#x2F;guides&#x2F;x64_cheatsheet.pdf&quot;&gt;source&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;registers.png&quot; alt=&quot;Register organization in x64&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;instruction-set-architecture&quot;&gt;Instruction Set Architecture&lt;&#x2F;h1&gt;
&lt;p&gt;The next important element is &lt;strong&gt;ISA&lt;&#x2F;strong&gt;, or &lt;em&gt;Instruction Set Architecture&lt;&#x2F;em&gt;. For CPUs to be useful,
they need to execute instructions. I define an instruction as a set of rules that specify
&lt;strong&gt;which operations&lt;&#x2F;strong&gt; to carry on and &lt;strong&gt;on what operands&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The ISA provides the set of such instructions the CPU can &lt;strong&gt;understand&lt;&#x2F;strong&gt; and &lt;strong&gt;execute&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This provides us with a powerful abstraction over CPU. Also, it enables us to view
the execution process as sequential, executing one instruction at a time. In reality, the modern CPUs
are quite sophisticated and even support executing multiple instructions simultaneously.&lt;&#x2F;p&gt;
&lt;p&gt;In conclusion, ISA is the asset for us to talk to the CPU.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;main-memory&quot;&gt;Main Memory&lt;&#x2F;h1&gt;
&lt;p&gt;One may note that registers are quite small and not enough for large sizes
of data our computers process on daily basis.&lt;&#x2F;p&gt;
&lt;p&gt;Thus, we need a larger memory, and it is called the &lt;em&gt;main memory&lt;&#x2F;em&gt;. However, compared to registers,
the access time to main memory is quite slow. This is a trade off.&lt;&#x2F;p&gt;
&lt;p&gt;For now, we assume that the main memory is a very large &lt;em&gt;array of bytes&lt;&#x2F;em&gt; we can &lt;strong&gt;address&lt;&#x2F;strong&gt; and &lt;strong&gt;access&lt;&#x2F;strong&gt;.
In fact, this is how our &lt;em&gt;programs&lt;&#x2F;em&gt; view the memory (moer about it later).&lt;&#x2F;p&gt;
&lt;p&gt;Keep in mind this assumption as it is &lt;em&gt;very important&lt;&#x2F;em&gt; in assembly.&lt;&#x2F;p&gt;
&lt;p&gt;Below is a diagram depicting the memory as Post Office boxes from the book &lt;em&gt;&lt;strong&gt;Programming From Ground up&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;.
As you can note, each box has an address (or, an identifier&#x2F;label) associated with it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;memory_as_po.png&quot; alt=&quot;Memory depicted as Post Office Box&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;One question arises: how do we address memory and how much can we have of memory? The answer is what the &quot;X&quot;
means when we say &quot;X-bit architecture&quot;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;what-x-means-in-x-bit-architecture&quot;&gt;What &quot;X&quot; means in &quot;X-bit architecture&quot;&lt;&#x2F;h1&gt;
&lt;p&gt;Looking at the organization of registers, one may note that X-bit system mainly has registers with capacity of X bits.
In other words, X-bit system can handle X-bit sized data at once.&lt;&#x2F;p&gt;
&lt;p&gt;Another meaning which follows from the size of registers is &lt;strong&gt;how many addresses&lt;&#x2F;strong&gt; we can have &lt;strong&gt;for&lt;&#x2F;strong&gt; our
&lt;strong&gt;memory locations&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Using basic counting from math, we can derive that 64-bit system can address 2^64 &lt;em&gt;&lt;strong&gt;bytes&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt; of memory. Note, this is not &lt;em&gt;bits&lt;&#x2F;em&gt;, but &lt;strong&gt;bytes&lt;&#x2F;strong&gt;.
This is because each memory location is &lt;strong&gt;one byte&lt;&#x2F;strong&gt; in &lt;em&gt;capacity&lt;&#x2F;em&gt;. In the analogy of Post Office Boxes,
we can have 2^64 boxes with &lt;strong&gt;unique addresses&lt;&#x2F;strong&gt; and each having 1 byte of capacity.&lt;&#x2F;p&gt;
&lt;p&gt;If you&#x27;re confused about addresses and calculation, think of addresses as &quot;labels&quot; to locations. So, we can label 2^X memory locations,
reuslting in memory as large as 2^X * capacity_of_single_location.&lt;&#x2F;p&gt;
&lt;p&gt;Subsequently, with 32 bits we can have memory as large as 2^32 * 1 byte ~= 4GB while with 64 bits theoretically we can have
16 exabytes!&lt;&#x2F;p&gt;
 &lt;!----&gt;


&lt;div
  class=&quot;my-4 flex flex-col rounded-lg bg-[var(--admonition-bg)]&quot;
  style=&quot;--admonition-bg: rgba(83, 211, 230, 0.1)&quot;
&gt;
  &lt;div class=&quot;flex items-center rounded-t-lg bg-[var(--admonition-bg)] p-1&quot;&gt;
    &lt;div
      class=&quot;mx-2 h-4 w-4 text-[0px] [background:var(--url)_center_center_no-repeat] dark:invert&quot;
      style=&quot;--url: url(.&#x2F;icons&#x2F;info.svg)&quot;
    &gt;
      info
    &lt;&#x2F;div&gt;
    &lt;span&gt;&lt;strong&gt;Main memory vs. Secondary memory&lt;&#x2F;strong&gt;&lt;&#x2F;span&gt;
  &lt;&#x2F;div&gt;
  &lt;div class=&quot;pl-4&quot;&gt;&lt;p&gt;&lt;strong&gt;Main memory&lt;&#x2F;strong&gt;: smaller, faster, and volatile (data is lost when a system goes off).
&lt;strong&gt;Secondary memory&lt;&#x2F;strong&gt;: larger, slower, and non-volatile (data persists).&lt;&#x2F;p&gt;
&lt;p&gt;As you may have noticed, the smaller is the memory, the faster it is; the larger is the memory, the slower it is (in terms of access time).
This is part of the &lt;em&gt;&lt;strong&gt;memory hierarchy&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The main memory can be in form of RAM, while secondary memory can be HDD, SSD, etc.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;p&gt;Our model so far...
&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;cpu_with_main_mem.png&quot; alt=&quot;Our CPU and memory model&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;intro-to-assembly&quot;&gt;Intro to Assembly&lt;&#x2F;h1&gt;
&lt;p&gt;Remember that the CPU&#x27;s main task is to fetch, decode, and execute instructions.
Reminding again, the ISA of each CPU provides instructions &lt;strong&gt;valid&lt;&#x2F;strong&gt; for that CPU.&lt;&#x2F;p&gt;
&lt;p&gt;Now, how do we write those instructions for CPUs?
As you may already know, CPUs only understand 0s and 1s, which is &lt;strong&gt;machine-language&lt;&#x2F;strong&gt;. Nothing more. Just bit patterns + &lt;strong&gt;context&lt;&#x2F;strong&gt; (with context, for example, numbers may
denote letters).&lt;&#x2F;p&gt;
&lt;p&gt;However, as humans, it could be burdensome to talk to CPUs in plain bits.
Here, the Assembly language gives us one higher level of abstraction and makes writing instructions much more
readable, essentially being a wrapper over the machine language.&lt;&#x2F;p&gt;
&lt;p&gt;As our instructions are based on the ISA of our machine, assembly written
for different ISAs is not the same, and incompatible.&lt;&#x2F;p&gt;
&lt;p&gt;Therefore, assembly is &lt;em&gt;&lt;strong&gt;machine-dependent&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;. In this sense, we can call assembly a &lt;em&gt;&lt;strong&gt;machine language&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt; to distinguish
from higher level languages such as C which are much more machine &lt;strong&gt;independent&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;There are many variations of assembly language, differing in syntax and some features. However, the
idea is the same: just write the instructions for the CPU.&lt;&#x2F;p&gt;
&lt;p&gt;I am going to use NASM syntax.&lt;&#x2F;p&gt;
&lt;p&gt;In the following sections, I write about the most essential assembly concepts, but without
giving full &lt;em&gt;program code&lt;&#x2F;em&gt;. Just bare plain concepts.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;movement-operations&quot;&gt;Movement operations&lt;&#x2F;h1&gt;
&lt;p&gt;The main operands of instructions is data. One of the most common operations we do is
data movement&#x2F;copy&#x2F;write&#x2F;read.&lt;&#x2F;p&gt;
&lt;p&gt;The instruction that copies data from one &lt;strong&gt;source&lt;&#x2F;strong&gt; to &lt;strong&gt;destination&lt;&#x2F;strong&gt; in assembly
is called &lt;code&gt;mov&lt;&#x2F;code&gt; with the following form:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov DATASIZE dest, src&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The operation copies bytes of amount specified using &lt;code&gt;DATASIZE&lt;&#x2F;code&gt; from source &lt;code&gt;src&lt;&#x2F;code&gt; to &lt;code&gt;dest&lt;&#x2F;code&gt;.
Although this definition covers all operand forms, we will see that there is subtlety in
how the process looks like depending on operand forms (the operands are &lt;code&gt;dest&lt;&#x2F;code&gt; and &lt;code&gt;src&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;Since we to specify data sizes and that they are very important in other instructions too,
the following section presents some of the data sizes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;common-data-sizes&quot;&gt;Common data sizes&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;&#x2F;th&gt;&lt;th&gt;Size&lt;&#x2F;th&gt;&lt;th&gt;Size (bits)&lt;&#x2F;th&gt;&lt;th&gt;NASM&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;byte&lt;&#x2F;td&gt;&lt;td&gt;1 byte&lt;&#x2F;td&gt;&lt;td&gt;8 bits&lt;&#x2F;td&gt;&lt;td&gt;op byte&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;word&lt;&#x2F;td&gt;&lt;td&gt;2 bytes&lt;&#x2F;td&gt;&lt;td&gt;16 bits&lt;&#x2F;td&gt;&lt;td&gt;op word&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;dword&lt;&#x2F;td&gt;&lt;td&gt;2 words&lt;&#x2F;td&gt;&lt;td&gt;32 bits&lt;&#x2F;td&gt;&lt;td&gt;op dword&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;qword (quad word)&lt;&#x2F;td&gt;&lt;td&gt;4 words&lt;&#x2F;td&gt;&lt;td&gt;64 bits&lt;&#x2F;td&gt;&lt;td&gt;op qword&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov dword dest, src&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This instructions reads 4 bytes of data from &lt;code&gt;src&lt;&#x2F;code&gt; and write 4 bytes to &lt;code&gt;dest&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;operand-and-instruction-forms&quot;&gt;Operand and instruction forms&lt;&#x2F;h2&gt;
&lt;p&gt;In assembly, there are mainly three types of operands:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;register&lt;&#x2F;li&gt;
&lt;li&gt;immediate&lt;&#x2F;li&gt;
&lt;li&gt;address in the &lt;em&gt;program&lt;&#x2F;em&gt; memory&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The instructions we write are:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;binary -- takes 2 operands&lt;&#x2F;li&gt;
&lt;li&gt;unary -- takes one operand&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The &lt;code&gt;mov&lt;&#x2F;code&gt; instruction is binary. Thus, its operands are the mix of three, with some combinations disallowed.&lt;&#x2F;p&gt;
&lt;p&gt;The following is the table of usage patterns.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Type&lt;&#x2F;th&gt;&lt;th&gt;Form&lt;&#x2F;th&gt;&lt;th&gt;Value in operation&lt;&#x2F;th&gt;&lt;th&gt;Meaning&lt;&#x2F;th&gt;&lt;th&gt;Explanation&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Immediate&lt;&#x2F;td&gt;&lt;td&gt;Imm&lt;&#x2F;td&gt;&lt;td&gt;Imm&lt;&#x2F;td&gt;&lt;td&gt;literal value&lt;&#x2F;td&gt;&lt;td&gt;-&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Register&lt;&#x2F;td&gt;&lt;td&gt;r&lt;&#x2F;td&gt;&lt;td&gt;R[r]&lt;&#x2F;td&gt;&lt;td&gt;Value stored in register &lt;code&gt;r&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;-&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mem&lt;&#x2F;td&gt;&lt;td&gt;[Imm]&lt;&#x2F;td&gt;&lt;td&gt;M[Imm]&lt;&#x2F;td&gt;&lt;td&gt;Value stored at memory address &lt;code&gt;Imm&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;-&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mem&lt;&#x2F;td&gt;&lt;td&gt;[r]&lt;&#x2F;td&gt;&lt;td&gt;M[R[r]]&lt;&#x2F;td&gt;&lt;td&gt;Value stored at memory address stored in &lt;code&gt;r&lt;&#x2F;code&gt;.&lt;&#x2F;td&gt;&lt;td&gt;The register &lt;code&gt;r&lt;&#x2F;code&gt; stores a memory address as its value.&lt;br&gt;&lt;br&gt;Writing [r] means that &lt;code&gt;r&lt;&#x2F;code&gt; stores memory address and instructs CPU to work on data stored in that address.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mem&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;[r1 + r2*k + Imm]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;M[R[ r1 ] + R[ r2 ] * k + Imm]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;This is arithmetic involving addresses.&lt;&#x2F;td&gt;&lt;td&gt;This form presents generic form for calculating address and accessing value starting at it in memory. For example, setting &lt;code&gt;k&lt;&#x2F;code&gt; and &lt;code&gt;Imm&lt;&#x2F;code&gt; to &lt;code&gt;0&lt;&#x2F;code&gt;, we obtain the (2) form in the table.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;The following are diagrams explaining behavior of &lt;code&gt;mov&lt;&#x2F;code&gt; operation involving different operand forms.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;immediate-to-register&quot;&gt;Immediate to register&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;mov_examples&#x2F;immediate.png&quot; alt=&quot;Copying immediate value to register&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;register-to-register&quot;&gt;Register to register&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Description:&lt;&#x2F;strong&gt; copies value from &lt;code&gt;src&lt;&#x2F;code&gt; register to &lt;code&gt;dst&lt;&#x2F;code&gt; register (note the size specifier).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;mov_examples&#x2F;reg2reg.png&quot; alt=&quot;Copying from register to register&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;&#x2F;strong&gt; the red underline is not accidental. This is one of  the special cases which is discussed later.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;memory-to-register&quot;&gt;Memory to register&lt;&#x2F;h3&gt;
&lt;p&gt;Suppose we have the number 1324 in the memory locations shown in the image below.
Such a signed integer is typically 4 bytes.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;1324 in binary: 10100101100&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To convert to hex, group the bits of the binary value by 4 from right to left and replace each group with hex equivalent.
Fill in zeros from left when number of bits in a group is not 4.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0101 0010 1100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 0x5  0x2  0xC =&amp;gt; 1324 in hex: 0x52c&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Joining them by 1 byte groups:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;00000101 00101100&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   0x5      0x2c&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;&#x2F;strong&gt; &#x27;0x&#x27; just denotes that the value is in hex.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;cp-arch-asm&#x2F;.&#x2F;mov_examples&#x2F;mem2reg.png&quot; alt=&quot;Copying from memory to register&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;&#x2F;strong&gt; You might have noticed little red asterisk. The sentence it is marking describes the behavior on one subtle case of &lt;code&gt;mov&lt;&#x2F;code&gt; operation. This will be discussed later.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;immediate-to-memory&quot;&gt;Immediate to memory&lt;&#x2F;h3&gt;
&lt;h3 id=&quot;register-to-memory&quot;&gt;Register to memory&lt;&#x2F;h3&gt;
&lt;h2 id=&quot;special-cases&quot;&gt;Special cases&lt;&#x2F;h2&gt;
&lt;h1 id=&quot;cmp-test-operations&quot;&gt;CMP&#x2F;TEST operations&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;conditions-flags&quot;&gt;Conditions&#x2F;FLAGS&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;conditional-branching-intro-to-jumps&quot;&gt;Conditional branching: Intro to Jumps&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;from-source-to-binary&quot;&gt;From Source to Binary&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;object-file-structure&quot;&gt;Object File Structure&lt;&#x2F;h2&gt;
&lt;h2 id=&quot;back-to-jumps&quot;&gt;Back to Jumps&lt;&#x2F;h2&gt;
&lt;h1 id=&quot;conditional-movement-operations&quot;&gt;Conditional movement operations&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;into-to-stack&quot;&gt;Into to Stack&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;hardware-manager-operating-system&quot;&gt;Hardware Manager: Operating System&lt;&#x2F;h2&gt;
&lt;h2 id=&quot;abstracting-hardware-process&quot;&gt;Abstracting hardware: Process&lt;&#x2F;h2&gt;
&lt;h2 id=&quot;abstracting-memory-virtual-address-space&quot;&gt;Abstracting Memory: Virtual Address Space&lt;&#x2F;h2&gt;
&lt;h2 id=&quot;back-to-stack&quot;&gt;Back to Stack&lt;&#x2F;h2&gt;
&lt;h1 id=&quot;some-interesting-things&quot;&gt;Some interesting things&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;resources&quot;&gt;Resources&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Coming soon.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Is your abstraction worth it?</title>
        <published>2025-08-31T00:00:00+00:00</published>
        <updated>2025-08-31T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              loga4m
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://loga4m.uz/is-your-abstraction-worth-it/"/>
        <id>https://loga4m.uz/is-your-abstraction-worth-it/</id>
        
        <content type="html" xml:base="https://loga4m.uz/is-your-abstraction-worth-it/"> &lt;!----&gt;


&lt;div
  class=&quot;my-4 flex flex-col rounded-lg bg-[var(--admonition-bg)]&quot;
  style=&quot;--admonition-bg: rgba(255, 145, 0, 0.1)&quot;
&gt;
  &lt;div class=&quot;flex items-center rounded-t-lg bg-[var(--admonition-bg)] p-1&quot;&gt;
    &lt;div
      class=&quot;mx-2 h-4 w-4 text-[0px] [background:var(--url)_center_center_no-repeat] dark:invert&quot;
      style=&quot;--url: url(.&#x2F;icons&#x2F;warning.svg)&quot;
    &gt;
      warning
    &lt;&#x2F;div&gt;
    &lt;span&gt;&lt;strong&gt;warning&lt;&#x2F;strong&gt;&lt;&#x2F;span&gt;
  &lt;&#x2F;div&gt;
  &lt;div class=&quot;pl-4&quot;&gt;&lt;p&gt;I would like you warn that this is somewhat lengthy post on my experience.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
&lt;h3 id=&quot;context&quot;&gt;Context&lt;&#x2F;h3&gt;
&lt;p&gt;Currently, I am working as a backend developer in our independent project.&lt;&#x2F;p&gt;
&lt;p&gt;During the development process, I observed that some queries were quite repetitive. Then, I also had to write a dedicated filtering functionality that creates &lt;strong&gt;chained select statements&lt;&#x2F;strong&gt; for applying all filters at once. Again, such filters turned out to be repetitive, and I was &lt;em&gt;&lt;strong&gt;thinking about utilizable functions&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;. Furthermore, in our DB scheme, we have tables that have a multi-language field (and thus several of it for specific languages). So, it made the filtering somehow more complicated.&lt;&#x2F;p&gt;
&lt;p&gt;As I had the mindset of &quot;utilizable functions&quot;, or tooling, or just &quot;as I see these queries repeat, I can create functions we can use in future too&quot; mindset, I built a whole DB tooling.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;examples-of-this-tooling&quot;&gt;Examples of this tooling&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; query_scalars_with_attrs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; dict[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; Any]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Select&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    filter_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; QueryTypes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; QueryTypes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;FILTER_EQUAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ScalarResult:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    A helper function that applies multiple attribute&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    filtering and queries the resultant `Select`.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;	...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a top-level function that abstracts applying filters and querying. Under the hood, well, it uses....&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; query_scalars&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Select&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ScalarResult:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    A function to apply `scalars` query on a given&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    base_s `Select`.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;	...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;.... another abstraction just for calling &lt;code&gt;session.scalars&lt;&#x2F;code&gt;!&lt;&#x2F;p&gt;
&lt;p&gt;Back to the first function. It only uses the second funtion at the end of its logic, after tasks like creating select statements are done. How does it make up select statements? Well, if you remember that its job is also filtering, it uses...&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; select_with_filter_multi_attr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; dict[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; Any]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Select&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    filter_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; QueryTypes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; QueryTypes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;FILTER_EQUAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;    validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; Select:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    A function to apply ORM filtering&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    functions. An ORM filtering is&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    detected based on &amp;#39;filter_type&amp;#39;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;	...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;... just another abstraction!&lt;&#x2F;p&gt;
&lt;p&gt;Now, what about these functions below:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; orm_filter_eq_multi_attr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Select&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; dict[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; Any]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; Select:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    A function to apply FILTER EQUAL in SQL.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; orm_ilike_multi_attr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Select&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; dict[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; Any]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; Select:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    A function to apply ILIKE in SQL, with&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;    &amp;#39;%value%&amp;#39; format.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;	...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;	&amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;	...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Cringe, yeah? By the way, there&#x27;s also an alternative to &lt;code&gt;select_with_filter_multi_attr&lt;&#x2F;code&gt; with support for multi-lingual query.... :)&lt;&#x2F;p&gt;
&lt;p&gt;But, wait, are not they doing some work? How did I decide this all was &quot;cringe&quot;?
Well...&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-reality&quot;&gt;The reality&lt;&#x2F;h3&gt;
&lt;p&gt;Let&#x27;s compare the functions and their alternatives in SQLAlchemy.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Ex1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITH the abstraction&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db_tools&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;query_scalars_with_attrs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;&amp;quot;public_id&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; author_public_id}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;first&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITHOUT the abstraction&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;scalar&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;	select&lt;&#x2F;span&gt;&lt;span&gt;(User)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;public_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; author_public_id)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;limit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A whole function just for literally a line of code (in fact).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Ex2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITH the abstraction&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;query_result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db_tools&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;query_scalars_with_attrs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	filter_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;QueryTypes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;ILIKE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;first&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITHOUT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;query_result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; session&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;scalar&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;	select&lt;&#x2F;span&gt;&lt;span&gt;(User)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;	.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;where&lt;&#x2F;span&gt;&lt;span&gt;(User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;ilike&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;&amp;quot;%&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;{&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;%&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;	.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;where&lt;&#x2F;span&gt;&lt;span&gt;(User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;surname&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;ilike&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF8F40;&quot;&gt;f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;{&lt;&#x2F;span&gt;&lt;span&gt;surname&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Quite elegant raw SQLAlchemy, yeah? Here is another example...&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# Ex3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITH the abstraction&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;orm_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; db_tools&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;select_with_filter_multi_attr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	model&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;Post&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	attrs_vals&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt;		&amp;quot;for_students&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;filters&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;for_students&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	base_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;orm_s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #5A6673;font-style: italic;&quot;&gt;# WITHOUT&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;orm_s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt; select&lt;&#x2F;span&gt;&lt;span&gt;(Post)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB454;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(Post&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;for_students&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F29668;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #39BAE6;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;filters&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BFBDB6B3;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;for_students)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;... This one was just &lt;strong&gt;nuclear&lt;&#x2F;strong&gt;, where one would become just &lt;em&gt;&lt;strong&gt;speechless&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt;!&lt;&#x2F;p&gt;
&lt;p&gt;Consider I wanted to be consistent in my query tooling. Then, with my abstraction, I would create another layer for other developers to learn my thing. Moreover, I would restrict everyone to what my functions did, what they accepted, etc. (If we want to be consistent.)&lt;&#x2F;p&gt;
&lt;p&gt;As we see from the comparisons, the core technologies (in this case SQLAlchemy) already provide very good abstractions.&lt;&#x2F;p&gt;
&lt;p&gt;Actually, I was very enthusiastic when was developing this tooling. Then, after such real comparison, I was just shocked --- I was doing all the work just to remove it. The real reality vs. expectation experience.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-reason-i-looked-back-and-questioned-what-i-have-created&quot;&gt;The reason I looked back and questioned what I have created&lt;&#x2F;h3&gt;
&lt;p&gt;Before I compared my functions and the raw SQLAlchemy abstractions, I think the reason I looked back at my tooling was that &lt;strong&gt;the abstraction was rigid&lt;&#x2F;strong&gt; when I moved to implement a pagination functionality. Simply, extending the functions was too much change as, crystal clear from the previous sections, the functions depended on another one by hierarchy.&lt;&#x2F;p&gt;
&lt;p&gt;So, this presented, &quot;Wait, what I have done just? Is it worth?&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;Besides the arguments I made for removing, you can note that these functions did too much validation. It&#x27;s just an overhead (well, even though I made the validation possible to turn off).&lt;&#x2F;p&gt;
&lt;p&gt;But, was this really useless? I think no. For two reasons.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;multi-lingual-select-and-basic-multi-attr-select&quot;&gt;Multi-lingual select and basic multi-attr select&lt;&#x2F;h3&gt;
&lt;p&gt;After the realization, I migrated to raw SQLAlchemy select&#x2F;queries. I cut my abstractions down to the database tooling and isolated it from other modules. Afterward, I started working on the filtering system.&lt;&#x2F;p&gt;
&lt;p&gt;When I was implementing filtering for multi-lingual fields, I realized that multi-lingual select abstraction was worth it.&lt;&#x2F;p&gt;
&lt;p&gt;The reason is that manually writing raw SQLAlchemy would create boilerplate. We can do multi-lingual filter across languages and find the best matches.&lt;&#x2F;p&gt;
&lt;p&gt;The abstraction exactly does that: it creates multiple select statements. The good part is that it can automatically check specific fields using a given &quot;root&quot; of these fields. If you want, you can specify priority language and also if the function should return a select statement for only that language.&lt;&#x2F;p&gt;
&lt;p&gt;I admit that I could eliminate that multi-field search enforcing a rule that a client must always specify the language they intend, or otherwise set a default language. Actually, the filtering system that uses this abstraction does so when calling it. Who knows, maybe there will be use of this clever function. Anyways, the abstraction is now &lt;strong&gt;isolated&lt;&#x2F;strong&gt; at the DB tooling level.&lt;&#x2F;p&gt;
&lt;p&gt;As for multi-attr select, I made its function signature start with &quot;&lt;code&gt;_&lt;&#x2F;code&gt;&quot;, implying it is not intended for an external use. It is used by multi-lingual select function. Although I can remove, I think it is for now good since it keeps the client function becoming too much lengthy.&lt;&#x2F;p&gt;
&lt;p&gt;I left another abstraction too. First, it is used by the multi-attr select function. Second, I didn&#x27;t change the usage as in the Ex2. comparison in &lt;a href=&quot;https:&#x2F;&#x2F;loga4m.uz&#x2F;is-your-abstraction-worth-it&#x2F;#the-reality&quot;&gt;The reality&lt;&#x2F;a&gt; section. It is just for &lt;em&gt;now&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now, the next reason is...&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-lesson&quot;&gt;The lesson&lt;&#x2F;h3&gt;
&lt;p&gt;I was almost devastated after realizing that I have spent at least a day working on that tooling. I had completely been driven by it and never had questioned. So, it taught a really big lesson.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some insights:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Question your abstractions. Repeating things does not always mean to create another abstraction.&lt;&#x2F;li&gt;
&lt;li&gt;Don&#x27;t be too much driven by enthusiasm. Try to keep rationality.&lt;&#x2F;li&gt;
&lt;li&gt;If you are not sure, compare your abstraction with the alternative without it.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Happy that I had this lesson. Thanks for reading!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Zola, Kita, Netlify &amp; Cloudflare setup -- a couple of &#x27;Why?&#x27;s</title>
        <published>2025-08-17T00:00:00+00:00</published>
        <updated>2025-08-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              loga4m
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://loga4m.uz/creating-blog/"/>
        <id>https://loga4m.uz/creating-blog/</id>
        
        <content type="html" xml:base="https://loga4m.uz/creating-blog/">&lt;h2 id=&quot;why-zola&quot;&gt;Why Zola?&lt;&#x2F;h2&gt;
&lt;p&gt;Actually, there is no need to stress over Zola, since I just wanted a blog website. I tried to create the blog in Python&#x2F;Flask (with templates). However, it comes with:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Setting up a database&lt;&#x2F;li&gt;
&lt;li&gt;Database backups&lt;&#x2F;li&gt;
&lt;li&gt;Deployment problems&lt;&#x2F;li&gt;
&lt;li&gt;Choosing a server&lt;&#x2F;li&gt;
&lt;li&gt;etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This obviously creates many problems for just a simle blog. Then, I had come across &lt;strong&gt;Static Site Generators&lt;&#x2F;strong&gt; which turned out to be a game-changer. I had started with &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;jekyllrb.com&#x2F;&quot;&gt;Jekyll&lt;&#x2F;a&gt; and spent some time learning it. It required setting up gems, ruby, and so on, though I truly respect the engineering behind it. I had dropped off this progress midway.&lt;&#x2F;p&gt;
&lt;p&gt;When I discovered Zola, it was something I needed:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Simple&lt;&#x2F;li&gt;
&lt;li&gt;Fast (built with Rust)&lt;&#x2F;li&gt;
&lt;li&gt;No assumptions about site structure&lt;&#x2F;li&gt;
&lt;li&gt;Tera (very similar to Jinja2, which i used in Flask templates)&lt;&#x2F;li&gt;
&lt;li&gt;Quick to setup&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So, just picked it up.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;kita&quot;&gt;Kita?&lt;&#x2F;h2&gt;
&lt;p&gt;I have explored available &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.getzola.org&#x2F;themes&#x2F;&quot;&gt;themes&lt;&#x2F;a&gt; with focus on minimal themes. The best quick matches were &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;st1020&#x2F;kita&quot;&gt;Kita&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;isunjn&#x2F;serene&quot;&gt;Serene&lt;&#x2F;a&gt;, and I&#x27;ve chosen &lt;strong&gt;Kita&lt;&#x2F;strong&gt; mainly for the following reasons:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Minimal&lt;&#x2F;li&gt;
&lt;li&gt;Organized by tags and date&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;tags&lt;&#x2F;code&gt; page replaces category complexity&lt;&#x2F;li&gt;
&lt;li&gt;Reader friendly: larger font, good colors, etc.&lt;&#x2F;li&gt;
&lt;li&gt;Quick to tweak&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;However, I should note that &lt;strong&gt;Kita&lt;&#x2F;strong&gt; may not be ideal for you since it makes some assumptions about structure. Still, you can adapt it because it runs on top of Zola, but you may need to spend some time on &lt;strong&gt;Kita&lt;&#x2F;strong&gt;&#x27;s ecosystem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;netlify&quot;&gt;Netlify?&lt;&#x2F;h2&gt;
&lt;p&gt;Yeah, Github Pages could be used, but Netlify was way simpler than Github Actions: link your github repo, deploy, and add your own domain, that&#x27;s all.
Used &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.getzola.org&#x2F;documentation&#x2F;deployment&#x2F;netlify&#x2F;&quot;&gt;Zola&#x27;s Netlify setup&lt;&#x2F;a&gt; docs for &lt;code&gt;netlify.toml&lt;&#x2F;code&gt; file.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;cloudflare&quot;&gt;Cloudflare?&lt;&#x2F;h2&gt;
&lt;p&gt;I have had my domain already connected to &lt;strong&gt;Cloudflare&lt;&#x2F;strong&gt; when I was using &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;cloudflare-one&#x2F;connections&#x2F;connect-networks&#x2F;&quot;&gt;Cloudflare tunneling&lt;&#x2F;a&gt; for exposing my development project to public (kinda cheating to premium tunneling tools like ngrok). So, it was just ready and I went with it.&lt;&#x2F;p&gt;
&lt;p&gt;Set up is simple:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add Netlify&#x27;s suggestions on custom domain settings&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;www CNAME&lt;&#x2F;code&gt; record to the netlify app URL&lt;&#x2F;li&gt;
&lt;li&gt;Add &lt;code&gt;ALIAS, flattened CNAME, or (I forgot the name)&lt;&#x2F;code&gt;&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#2&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt; record with Netlify&#x27;s own server (it was &lt;code&gt;apex-load-bala...&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Wait for changes to propagate&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;&#x2F;sup&gt;
&lt;p&gt;In your provider&#x27;s (in my case Cloudflare) DNS Records settings&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;2&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;&#x2F;sup&gt;
&lt;p&gt;Netlify says these two are &lt;em&gt;more resilient&lt;&#x2F;em&gt; than fallback options (in my case, was &lt;code&gt;A record&lt;&#x2F;code&gt;)&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;A simple blog with fast setup, no DB, and no deployment headaches.
Respect for all engineers who made Netlify, GitHub, Cloudflare, and SSGs possible!&lt;&#x2F;p&gt;
</content>
        
    </entry>
</feed>
