Operating System completed in 10 minutes
Do you believe that there can be less than 20 lines of code for an "Operating System?
Example 1. Chapter1/A/boot. ASM
1 org 07c00h; tells the compiler program to load at 7c00
2 mov ax, CS
3 mov ds, ax
4 mov es, ax
5 call dispstr; call the display string routine
6 JMP $; infinite loop
7 dispstr:
8 mov ax, bootmessage
9 mov bp, ax; es: BP = string address
10 mov CX, 16; Cx = String Length
11 mov ax, 01301 h; Ah = 13, Al = 01 H
12 mov BX, 000ch; page number is 0 (bH = 0) black background red letter (BL = 0ch, highlighted)
13 mov DL, 0
14 int 10 h; 10 h interrupted
15 RET
16 bootmessage: DB "hello, Guest OS success world !"
17 times 510-($-$) db 0; fill in the remaining space to make the generated binary code exactly 512 bytes
1 8 DW 0xaa55; End mark
Compile the code using NASM:
$ NASM boot. ASM-O boot. Bin
We get a 512-byte boot. bin. Let's use the absolute sector read/write tool to write this file to the first sector of a blank floppy disk. In Linux, you can do this:
$ Dd If = boot. bin of =/dev/fd0 BS = 512 COUNT = 1
In Windows, you can do this:
$ Rawrite2.exe-F boot. Bin-D
Now, your first "Operating System" has been completed. This floppy disk is already a boot disk.
Put it in your drive and restart your computer. boot from a floppy disk. What do you see?
The computer shows your string! Red "Hello, OS world !", What a wonderful thing! Your "Operating System" is running!
If you use a virtual machine such as bochs (a detailed introduction to bochs will be provided below), you can read the specific results in this book.
This is really great. Although you know how simple it is, after all, you have made a bootable floppy disk and you have done all the work independently!
This article is excerpted from the book Orange's: the implementation of an operating system.