The ORG pseudo-Command tells the assembler that my program will be loaded to address A in the future, so in the compilation *Absolute address* Add A to the current offset.
The following is an example of a bootloader that displays a string on the screen.
[Bits 16] <br/> [org 0x7c00] <br/> mov cx, 12 <br/> mov dx, 0 <br/> mov ax, 01301 h <br/> mov bx, 0004 h <br/> mov bp, msg <br/> int 10 h <br/> jmp $ <br/> msg db'hello world! '<Br/> times 510-($-$) db 0 <br/> dw 0xaa55
If the second line is not commented out, the compiled file is displayed with hexdump-C.
ABCD @ Ubuntu :~ $ NASM-F bin blog. ASM-O blog. IMG <br/> ABCD @ Ubuntu :~ $ Hexdump-C blog. IMG <br/> 00000000 B9 0C 00 Ba 00 00 B8 01 13 BB 04 00 BD 14 7C CD | .............. |. | <br/> 00000010 10 E9 fd ff 68 65 6C 6C 6f 20 77 6f 72 6C 64 21 | .... hello world! | <Br/> 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ | <br/> * <br/> 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA | ............ .. u. | <br/> 00000200 <br/>
Comment the second line. The compiled file is
Abcd @ ubuntu :~ $ Nasm-f bin blog. asm-o blog. img <br/> abcd @ ubuntu :~ $ Hexdump-C blog. img <br/> 00000000 b9 0c 00 ba 00 00 b8 01 13 bb 04 00 bd 14 00 cd | ................ | <br/> 00000010 10 e9 fd ff 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 | .... hello world! | <Br/> 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ | <br/> * <br/> 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa | ............ .. u. | <br/> 00000200 <br/>
Mov bp and msg in two cases, the compiled machine code is bd 14 7c and bd 14 00 respectively.
In a virtual machine, if the compiled file is used as a virtual floppy disk to start the Virtual Machine (virtualbox), the first program will display the normal hello world on the screen!
The second one is garbled.