@@ 106,33 106,19 @@ along, I’m going to explain things in a “need to know” basis.
First, the `BITS 16` line tells NASM that we want to compile code in real mode.
This code below runs not only on a i386, but on any CPU of the x86 family,
-including the original 8086.</p><p>The `org 0x7c00` directive tells NASM that
-this code will run at offset `0x7c00` in memory. Without this, the `msg`
-reference below will be wrong[^10] because NASM will think that `msg` lives
-somewhere near address zero.
+including the original 8086.
-The next two lines go together and have the effect of setting the `ES` register
-to zero. `ES` is a special “segment” register allowing the original 8086 to
-address more than 64 kilobytes of memory (the maximum 16-bit address). The idea
-is that “segment registers” such as `ES`[^11] moves the address window by 16
-times its value. For example, if `ES` is 1, then calling `int10h` below with
-`BP=0` will effectively reference absolute address `0x10`. A bit confusing? I
-told you you’d swear. We won’t be doing anything fancy with segments in 16-bit
-mode, no need to think too much of it.
-
-Anyways, for the `msg` reference below to work, we need `ES` to be zero[^12].
-There are no form of `mov` instruction allowing an immediate[^13] source
-argument with a "segment register" destination argument, so we need to set
-another register to zero, `AX` in this case, and then set `ES` with the value
-of `AX`.
+The `org 0x7c00` directive tells NASM that this code will run at offset
+`0x7c00` in memory. Without this, the `msg` reference below will be wrong[^10]
+because NASM will think that `msg` lives somewhere near address zero.
-The following 8 lines are arguments setup for the BIOS function
+Most of the following lines are arguments setup for the BIOS function
[INT10h][int10h]. We’ll talk about interrupts in more details later, but for
now, what you should know is that BIOS functions are called through the `int`
instruction which triggers a software interrupt of the specified index.
Arguments to BIOS functions are passed through specific registers. The most
-important argument is `AH`[^14] because it specifies the subfunction to call
-and thus the nature of the call. In this instance, “INT10h AH=0x13” means, as
+important argument is `AH`[^11] because it specifies the subfunction to call
+and thus the nature of the call. In this instance, “INT10h AH=0x13” means, as
you can see in the documentation, “Write string”. Most of the other arguments
are self-explanatory. As you can see, the `msg` label is used as a source
argument for `mov`. When assembling, NASM will calculate the offset where `msg`
@@ 144,9 130,28 @@ The `int 0x10` line triggers the interrupt handler `0x10`, which lives in the
BIOS. This is the equivalent of a `call` and will return once it’s finished
doing its thing.
-The next line is an infinite loop because we don’t have anything to do after
-after having written the string. It defines a new label and jumps to it, which
-means it’s stuck there forever.
+Let's go back to `mov ax, 0; mov es, ax` which warrant a special mention. They
+aren't precisely part of the `int10h` argument setup, but rather the system
+memory setup.
+
+These lines go together and have the effect of setting the `ES` register to
+zero. `ES` is a special “segment” register allowing the original 8086 to
+address more than 64 kilobytes of memory (the maximum 16-bit address). The idea
+is that “segment registers” such as `ES`[^12] moves the address window by 16
+times its value. For example, if `ES` is 1, then calling `int10h` below with
+`BP=0` will effectively reference absolute address `0x10`. A bit confusing? I
+told you you’d swear. We won’t be doing anything fancy with segments in 16-bit
+mode, no need to think too much of it.
+
+Anyways, for the `msg` reference below to work, we need `ES` to be zero[^13].
+There are no form of `mov` instruction allowing an immediate[^14] source
+argument with a "segment register" destination argument, so we need to set
+another register to zero, `AX` in this case, and then set `ES` with the value
+of `AX`.
+
+The line following `int 0x10` is an infinite loop because we don’t have
+anything to do after after having written the string. It defines a new label
+and jumps to it, which means it’s stuck there forever.
The next two lines are data and are never executed. `db` is a special NASM
directive to write literal data into the executable and this directive supports
@@ 226,15 231,15 @@ if your machine was booting up from the HDD.
[^10]: The “loop” one will be fine though because all jumps use relative
adressing. More on this later.
-[^11]: There are many such registers that serve in different contexts.
+[^11]: Each 8086 “general” register, AX, BX, CX, DX, are divided in two “H”
+(high) and “L” (low) 8-bit sub-registers.
+
+[^12]: There are many such registers that serve in different contexts.
-[^12]: Another way to proceed would be to keep “org” to zero and then set “ES”
+[^13]: Another way to proceed would be to keep “org” to zero and then set “ES”
to 0x7c0.
-[^13]: "constant” in layman terms.
-
-[^14]: Each 8086 “general” register, AX, BX, CX, DX, are divided in two “H”
-(high) and “L” (low) 8-bit sub-registers.
+[^14]: "constant” in layman terms.
[^15]: But not for the whole story arc, as we’ll soon dive into the worderful
world of Forth, which OSdev doesn’t cover.
@@ 154,7 154,7 @@ complex than a Forth. If you end up on that path, come back here! We have a
Forth to write.
[^2]: That’s the key word here. A majority of the possible combinations lead to
abominations.
-[^3]: In traditional Forths, steps 2 and 3 are inverted, but I personally
+[^3]: In traditional Forths, steps 2 and 4 are inverted, but I personally
prefer that order. More on this later.
[^4]: We’ll see what it is later.
[^5]: Also for later.
@@ 41,7 41,8 @@ I reach that amount, I write a new arc.
</p>
<p>
If you appreciate what I write and would contribute to me writing some more of
-this stuff, please contribute.
+this stuff, please contribute. Although 20$ is suggested, any amount you find
+appropriate is accepted.
</p>
<script async
src="https://js.stripe.com/v3/buy-button.js">