Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

x86 bootloader NASM question.

gazdascheffgazdascheff Member Posts: 1
Every tutorial on writing bootloaders included the [BITS 16] and [ORG 0x7C00] directives. But one tutorial didn't, and the code worked. Here it is:

pop es
xor di, di
mov [es:di], word 441h

jmp $

times 510 - ($-$$) db 0
db 55h
db 0AAh

It puts a red A on the screen (not important).

Why does this work without the directives? (worked in virtual machine, didn't try hardware)

Comments

  • anthrax11anthrax11 Member Posts: 511
    Nasm defaults to 16-bit instructions when using the binary output format, so removing [BITS 16] has no effect.

    Removing [ORG 0x7C00] works, because the resulting code is position independent. The org directive helps to make it clear that the bootloader is loaded and runs at that particular address. The jmp instruction here is relative, it doesn't jump to a specific address, but rather just 2 bytes backwards in the command stream (ending up in an infinite loop). So it doesn't matter where in memory the code is, it still behaves the same way.
Sign In or Register to comment.