<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pierre on Medium]]></title>
        <description><![CDATA[Stories by Pierre on Medium]]></description>
        <link>https://medium.com/@pierre.ansar?source=rss-93afbbc3e699------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3Rt77Gc00CmiseN-H23o8A.png</url>
            <title>Stories by Pierre on Medium</title>
            <link>https://medium.com/@pierre.ansar?source=rss-93afbbc3e699------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:05:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pierre.ansar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Base register in x86–64 assembly: understanding RBX, EBX, BX, BH and BL]]></title>
            <link>https://medium.com/@pierre.ansar/the-base-register-in-x86-64-assembly-understanding-rbx-ebx-bx-bh-bl-260e8e215a98?source=rss-93afbbc3e699------2</link>
            <guid isPermaLink="false">https://medium.com/p/260e8e215a98</guid>
            <category><![CDATA[processors]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Pierre]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 21:13:24 GMT</pubDate>
            <atom:updated>2025-02-02T21:13:53.328Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether you’re just beginning to learn about assembly language and computer architecture, aiming to deepen your knowledge of systems, or becoming a reverse engineer, you’ve likely heard about CPU registers. Each CPU core has its own set of registers that hold values temporarily during program execution. This article will specifically examine the base register, commonly referred to as the BX register, along with its 32-bit extension, EBX, and its modern 64-bit counterpart, RBX.</p><h4>What is a CPU register?</h4><p>A register is a fast type of <strong>computer memory</strong>. Accessing data held in a register is much faster than accessing data from RAM, which in turn is faster than retrieving bits stored on the computer’s hard disk. There are different types of registers, and the one we will discuss in this article is a general-purpose register. Data stored in registers is not meant to be persistent, in fact, the contents of each register change very frequently as the running process executes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/0*dPQYHocDLgUyk2tO.png" /><figcaption>Computer memory types, picture from <a href="https://www.vlsifacts.com/classification-of-semiconductor-memories-and-computer-memories/">https://www.vlsifacts.com/classification-of-semiconductor-memories-and-computer-memories/</a></figcaption></figure><h4>What is the base register (BX)?</h4><p>The base register is a general-purpose register, meaning it can be used for many different purposes, even though there are some conventions for its usage. The difference between RBX, EBX, and BX is their size. On 32-bit architectures, EBX (extended BX) used to be the full register since it is 32 bits long. However, on modern 64-bit processors, RBX is now the full 64-bit register, and EBX represents the lower 32 bits of this register. On both architectures, BX is the lower 16-bit part of the base register, BH is the upper 8-bit part (H stands for &quot;high&quot;), and BL represents the lower 8-bit part (L for &quot;low&quot;).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5X9BtkW6mFn4b-_g9h3JCw.png" /></figure><h4>What is the data segment?</h4><p>The base register has historically been used to point to the address of the data segment. In assembly, the data segment allows you to declare values stored in RAM before the system calls the program’s entry point. This is often used to declare global and static variables that are initialized by the programmer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*g4nXriCpkHzjFj6kk-nMnQ.png" /><figcaption>Memory segments</figcaption></figure><p>Here is the most classic example of using the data segment, where we store the string “Hello World” (including the newline character by adding 10 which is A in hexadecimal after the string) and the length of the string:</p><pre>section        .data             <br>    msg        db &quot;Hello world!&quot;, 0xA<br>    len        equ $ -msg </pre><h4>What are the roles of the base register?</h4><p>This register is a general-purpose register with multiple uses. It is commonly used for various types of computation and storage. Among its different uses, the most important ones include:</p><ul><li><strong>Pointing to the address of the data segment</strong>. Since all data stored in memory is placed in contiguous addresses in RAM, having the base address of the data segment allows us to retrieve any data in this segment by simply performing an addition. On 32-bit architecture, this address is stored in EBX.</li><li>When making a <strong>system call </strong>on 32-bit architecture, the first argument of the syscall is stored in the base register. However, in today’s 64-bit systems, system call arguments are not stored in RBX and RCX. Instead, they are saved in RSI, RDI, RDX, R10, R8, and R9. Here is an example of a program using the write syscall, storing the first argument of this syscall (the file descriptor, in this case stdout) in EBX.</li></ul><pre>mov edx,len  ; message length<br>mov ecx,msg  ; message to write<br>mov ebx,1  ; file descriptor (stdout)<br>mov eax,4  ; system call number (sys_write)<br>int 0x80  ; call kernel</pre><p>Here is the man for the write system call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBtLD7QRXgcsD05jzqGBJA.png" /></figure><ul><li>Finally, this general-purpose register can also be used to temporarily store values and perform arithmetic operations with it, just like other general-purpose registers.</li></ul><h4>Conclusion</h4><p>The base register (RBX/EBX/BX/BH/BL) is essential to x86 assembly programming. Note that it is a <strong>callee-saved register</strong>, meaning its value should be preserved across function calls, with the callee responsible for saving and restoring it. On 32-bit architecture, the full register was EBX (extended BX); however, in today&#39;s world, most architectures are 64-bit, and now the complete register is named RBX.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=260e8e215a98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Accumulator register in x86–64 assembly: understanding RAX, EAX, AX, AH, and AL]]></title>
            <link>https://medium.com/@pierre.ansar/the-accumulator-register-in-x86-64-assembly-understanding-rax-eax-ax-ah-and-al-0deb18032778?source=rss-93afbbc3e699------2</link>
            <guid isPermaLink="false">https://medium.com/p/0deb18032778</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[processors]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[assembly]]></category>
            <dc:creator><![CDATA[Pierre]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 09:41:15 GMT</pubDate>
            <atom:updated>2025-01-31T09:55:07.883Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve just started learning about assembly and computer architecture, whether to deepen your understanding of systems or to become a master at reverse engineering — you’ve certainly come across CPU registers.Each CPU core has its own set of registers that store values during program execution. In this article, we will focus on the accumulator register, also known as the AX register, its 32-bit extended version EAX, and its modern 64-bit version RAX.</p><h4>What is a CPU register?</h4><p>A register is a fast type of <strong>computer memory</strong>. Accessing data held in a register is much faster than accessing data from RAM, which in turn is faster than retrieving bits stored on the computer’s hard disk. There are different types of registers, and the one we will discuss in this article is a general-purpose register. Data stored in registers is not meant to be persistent, in fact, the contents of each register change very frequently as the running process executes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/0*dPQYHocDLgUyk2tO.png" /><figcaption>Computer memory types, picture from <a href="https://www.vlsifacts.com/classification-of-semiconductor-memories-and-computer-memories/">https://www.vlsifacts.com/classification-of-semiconductor-memories-and-computer-memories/</a></figcaption></figure><h4>What is the Accumulator register (AX)?</h4><p>The accumulator register is a general-purpose register. The difference between RAX, EAX, and AX is <strong>their size</strong>. On 32-bit architectures, EAX (extended AX) used to be the full register since it is 32 bits long. However, on modern 64-bit processors, RAX is now the full 64-bit register, and EAX represents the lower 32 bits of this register. On both architectures, AX is the lower 16-bit part of the accumulator register, AH is the upper 8-bit part (H stands for “high”), and al represents the lower 8 bits (L for “low”).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSTOKsqSfpKLxrFEr2BY2Q.png" /></figure><h4>What are the roles of this register?</h4><p>This register is a general-purpose register with multiple uses. It is commonly used for various types of computation and storage. Among its different uses, the most important ones include:</p><ul><li>Storing the <strong>return value of functions</strong>. In fact, when you use the instruction return x<em> </em>in C for example, x is loaded into RAX/EAX.</li></ul><p>Here is an example of C code translated into x86–64 assembly:</p><pre>int add(int a, int b) {<br>    return a+b;<br>}</pre><pre>add:<br>        push    rbp<br>        mov     rbp, rsp<br>        mov     DWORD PTR [rbp-4], edi<br>        mov     DWORD PTR [rbp-8], esi<br>        mov     edx, DWORD PTR [rbp-4]<br>        mov     eax, DWORD PTR [rbp-8]<br>        ; stores the result of a+b by adding edx (a) to eax (b)<br>        add     eax, edx<br>        pop     rbp<br>        ret</pre><ul><li>When making a <strong>system call</strong>, the syscall number must be stored in the accumulator register. In the following example, the write syscall is used to write to the standard output. Since, on most 32-bit Unix distributions, the syscall number for write is 4, we store 4 in the eax register.</li></ul><pre>mov edx,4  ; message length<br>mov ecx,msg  ; message to write<br>mov ebx,1  ; file descriptor (stdout)<br>mov eax,4  ; system call number (sys_write)<br>int 0x80  ; call kernel</pre><p>Here is the man for the write system call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBtLD7QRXgcsD05jzqGBJA.png" /></figure><ul><li>Historically, the AX register was used as the primary register for arithmetic and data operations in early x86 and predecessor architectures. Its name comes from its frequent use in <strong>accumulating</strong> the results of computations. Today, it is still heavily used for mathematical operations. For example, if you use the instruction imul ecx (one operand), the calculation performed will be EAX * ECX, and the high 32 bits of the result will be written to the EDX register and the low 32 bits to the EAX register. This is the exact role of an accumulator, EAX plays at the same time the role of input and output. The same logic applies to various mathematical instructions in the x86 assembly instruction set.</li><li>Finally, this general-purpose register can also be used to temporarily store values, just like other general-purpose registers.</li></ul><h4>Conclusion</h4><p>The accumulator register (RAX/EAX/AX/AH/AL) plays a fundamental role in x86–64 assembly programming, it’s a key component in arithmetic operations, returning function values, and making system calls. On 32-bit architecture, the full register was EAX (extended AX), however in today’s world most architectures are 64-bit and now the complete register is named RAX.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0deb18032778" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>