From a3ae9e5d0ed8aa1ab10f559ee04916ec8aec89d4 Mon Sep 17 00:00:00 2001 From: Crystal Date: Thu, 7 Mar 2024 20:55:36 +0100 Subject: Add stuff --- blog/asm/1.html | 77 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 36 deletions(-) (limited to 'blog/asm') diff --git a/blog/asm/1.html b/blog/asm/1.html index c4b0bf6..d46759f 100644 --- a/blog/asm/1.html +++ b/blog/asm/1.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + x86 Assembly from my understanding @@ -23,9 +23,9 @@

Soooo this article (or maybe even a series of articles, who knows ?) will be about x86 assembly, or rather, what I understood from it and my road from the bottom-up hopefully reaching a good level of understanding

-
-

Memory :

-
+
+

Memory :

+

Memory is a sequence of octets (Aka 8bits) that each have a unique integer assigned to them called The Effective Address (EA), in this particular CPU Architecture (the i8086), the octet is designated by a couple (A segment number, and the offset in the segment)

@@ -40,9 +40,9 @@ Memory is a sequence of octets (Aka 8bits) that each have a unique integer assig The offset and segment are encoded in 16bits, so they take a value between 0 and 65535

-
-

Important :

-
+
+

Important :

+

The relation between the Effective Address and the Segment & Offset is as follow :

@@ -52,8 +52,8 @@ The relation between the Effective Address and the Segment & Offset is as fo

    -
  • Example :
    -
    +
  • Example :
    +

    Let the Physical address (Or Effective Address, these two terms are enterchangeable) 12345h (the h refers to Hexadecimal, which can also be written like this 0x12345), the register DS = 1230h and the register SI = 0045h, the CPU calculates the physical address by multiplying the content of the segment register DS by 10h (or 16) and adding the content of the register SI. so we get : 1230h x 10h + 45h = 12345h

    @@ -66,16 +66,16 @@ Now if you are a clever one ( I know you are, since you are reading this <3 )
-
-

Registers

-
+
+

Registers

+

The 8086 CPU has 14 registers of 16bits of size. From the POV of the user, the 8086 has 3 groups of 4 registers of 16bits. One state register of 9bits and a counting program of 16bits inaccessible to the user (whatever this means).

-
-

General Registers

-
+
+

General Registers

+

General registers contribute to arithmetic’s and logic and addressing too.

@@ -126,28 +126,28 @@ Now here are the Registers we can find in this section:
-
-

Addressing and registers…again

-
+
+

Addressing and registers…again

+
-
-

I realized what I wrote here before was almost gibberish, sooo here we go again I guess ?

-
+
+

I realized what I wrote here before was almost gibberish, sooo here we go again I guess ?

+

Well lets take a step back to the notion of effective addresses VS relative ones.

-
-

Effective = 10h x Segment + Offset . Part1

-
+
+

Effective = 10h x Segment + Offset . Part1

+

When trying to access a specific memory space, we use this annotation [Segment:Offset], so for example, and assuming DS = 0100h. We want to write the value 0x0005 to the memory space defined by the physical address 1234h, what do we do ?

    -
  • Answer :
    -
    +
  • Answer :
    +
    MOV [DS:0234h], 0x0005
     
    @@ -155,11 +155,16 @@ When trying to access a specific memory space, we use this annotation [Segmen

    Why ? Let’s break it down : -lain-dance.gif

    +
    +

    lain-dance.gif +

    +
    + +

    We Already know that Effective = 10h x Segment + Offset, So here we have : 1234h = 10h x DS + Offset, we already know that DS = 0100h, we end up with this simple equation 1234h = 1000h + Offset, therefor the Offset is 0234h

    @@ -172,9 +177,9 @@ Simple, right ?, now for another example
-
-

Another example :

-
+
+

Another example :

+

What if we now have this instruction ?

@@ -187,9 +192,9 @@ What does it do ? You might or might not be surprised that it does the exact sam

-
-

Segment + Register <3

-
+
+

Segment + Register <3

+

Consider DS = 0100h and BX = BP = 0234h and this code snippet:

@@ -225,8 +230,8 @@ The General rule of thumb is as follows :
    -
  • Note
    -
    +
  • Note
    +

    The values of the registers CS DS and SS are automatically initialized by the OS when launching the program. So these segments are implicit. AKA : If we want to access a specific data in memory, we just need to specify its offset. Also you can’t write directly into the DS or CS segment registers, so something like

    @@ -244,7 +249,7 @@ The values of the registers CS DS and SS are automatically initialized by the OS

    Author: Crystal

    -

    Created: 2024-03-07 Thu 20:54

    +

    Created: 2024-03-07 Thu 20:55

    -- cgit 1.4.1-2-gfad0