0

As we know, the first step in mbr is to set the segment register to 0. But there can be two methods to set the segment register, first we can use "xorw %ax, %ax" to set AX to 0, and second we can use "movw %cs, %ax" to set AX, then we will use the AX register to set other segment registers, ds, es, ss. The question is whether these two writing methods have any impact on the subsequent code of MBR.
enter image description here
enter image description here

If it has an effect, I want to know what is the effect. Well, if not, I want to know why it hasn't an effect.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
ruoqiu
  • 1
  • 2
    Never copy CS to other segment registers. The BIOS doesn't guarantee that the CS will actually be zero (some BIOSes may use a value of 0x7c0 in CS, and others 0x0000). Whatever value it has it should not be relied on. If you set ORG to 0x7c00 then set the segment registers to zero as 0x0000<<4+0x7c00=physical address 0x7c00. If you use ORG 0x0000 then set the segment registers to 0x07c0<<4+0x0000=physical address 0x7c00. – Michael Petch Mar 06 '23 at 03:35
  • I recommend using an ORG of 0x7c00 and set the segment registers to zero. This eliminates headaches when setting up a GDT and jumping into protected mode. If you see code that copies the CS value that the BIOS used when calling your MBR I recommend finding another tutorial. – Michael Petch Mar 06 '23 at 03:37
  • 1
    If you are new to x86 16-bit real mode assembly and don't know much about segment:offset addresses then this is a good guide/tutorial: https://thestarman.pcministry.com/asm/debug/Segments.html – Michael Petch Mar 06 '23 at 03:38
  • I have some general bootloader tips in this Stackoverflow answer: https://stackoverflow.com/a/32705076/3857942 – Michael Petch Mar 06 '23 at 03:42
  • thanks for your answer and learning resource – ruoqiu Mar 06 '23 at 09:26
  • Hello and welcome to Stack Overflow. Please read [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/questions/285551/why-should-i-ot-upload-images-of-code-data-errors) to see how you can improve your question. – Andy Preston Mar 06 '23 at 10:48

0 Answers0