The compilation language compiler we used this time was developed by the author of the original book, called NASK. Many syntaxes are very similar to the famous compilation language compiler NASM. Because the author of the original book did not give any difference, it cannot be different here! Now we only need to use the DB commands in the assembly language to write an "Operating System. The DB command is short for "define Byte". It writes 1 byte of ultra-long source code to the file.
1 dB 0xeb, 0x4e, 0x90, 0x48, 0x45, 0x4c, 0x4c, 0x4f2 db 0x49, 0x50, 0x4c, 0x00, 0x02, 0x01, 0x01, 0x003 db 0x02, 0xe0, 0x00, 0x40, 0x0b, 0xf0, 0x09, 0x004 db 0x12, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x005 db 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x29, 0xff6 7 here the 0.18 million 4314 rows in the middle are omitted 8 9 dB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
View code
Save as helloos. NAS, execute the following command to compile it into helloos. IMG .. \ z_tools \ nask.exe helloos. NAS helloos. IMG (I entered the red line) and then put helloos. put IMG in qemu on the author's CD to run it! Since the above Code is too long, it is simply horrible! To shorten the code length. Use a new resbresb command to write "reserve Byte" and fill the byte with 0x00. If you want to fill in 10 0x00 in the following address, you can write the source code of resb 10 normal length
1 DB 0xeb, 0x4e, 0x90, 0x48, 0x45, 0x4c, 0x4c, 0x4f 2 DB 0x49, 0x50, 0x4c, 0x00, 0x02, 0x01, 0x01, 0x00 3 DB 0x02, 0xe0, 0x00, 0x40, 0x0b, 0xf0, 0x09, 0x00 4 DB 0x12, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 5 DB 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x29, 0xff 6 DB 0xff, 0xff, 0xff, 0x48, 0x45, 0x4c, 0x4c, 0x4f 7 DB 0x2d, 0x4f, 0x53, 0x20, 0x20, 0x20, 0x46, 0x41 8 DB 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00 9 RESB 1610 DB 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c11 DB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a12 DB 0x04, 0x83, 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x0913 DB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb14 DB 0xee, 0xf4, 0xeb, 0xfd, 0x0a, 0x0a, 0x68, 0x6515 DB 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x7216 DB 0x6c, 0x64, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x0017 RESB 36818 DB 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa19 DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0020 RESB 460021 DB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0022 RESB 1469432
View code
Save as helloos1.nas and run the following command to compile it into helloos1.img .. \ z_tools \ nask.exe helloos1.nas helloos1.img. Then put helloos1.img in the qemu on the author's CD! The running result is the same as above, so it won't work! Although the source program of the normal length has become short, it is still against humanity and cannot be read. The following process shows the source code with a pattern.
; Hello-OS; below is the code dB 0xeb, 0x4e, 0x90 dB "helloipl" dedicated to floppy disks in the standard fat12 format; Name of the startup zone, 8-byte DW 512; the size of each slice must be 512-byte dB 1; the size of the cluster must be 1-sector DW 1; the starting position of the fat (generally starting from 1st sectors) DB 2; the number of fat (must be 2) DW 224; the root directory size (usually set to 224 items) DW 2880; the disk size (must be 2880 sectors) dB 0xf0; disk Type (must be 0xf0) DW 9; fat length (must be 9 sectors) DW 18; one track has several sectors (must be 18) DW 2; the number of magnetic heads (must be 2) dd 0; no partitions, must be 0 dd 2880; the disk size db 0, 0x29 is overwritten once; The significance is unknown, fixed dd 0 xffffffff; it may be the volume number DB "hello-OS", the disk name (11 bytes) dB "fat12", the disk format name (8 bytes) resb 18, and 18 bytes blank; database 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c dB 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a db 0x04, 0x83, 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09 dB 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb dB 0xEE, 0xf4, 0xeb, 0xfd; Information Display Section dB 0x0a, 0x0a; 2 line breaks DB "hello, world "DB 0x0a; Wrap db 0 resb 0x1fe-$; fill 0x00 data until 0x001fe db 0x55, 0xaa; below are the output dB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 resb 4600 dB 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 resb 1469432
View code
In the source code above, ";" indicates the meaning of a comment. If NASK sees ";", the text after the character will not be parsed, so that programmers can check that the DW command is short for "Default word, each time a word (2 bytes) long content can be written, because in the language world of computer assembly, word refers to 16 bits, that is, the 2-byte DW command is short for "Default double-word". Each time a dual-word (4-byte) Long resb 0x1fe-$, $ is a global variable that saves the number of bytes that the above Code has filled. To ensure that this line of code is executed, 0x1fe bytes at the first level are filled with the corresponding data. Why 0x1fe? Because the computer first reads data from the first sector (512 bytes = 0x200). If the last two bytes of this sector are 0x55 0xaa, a startup program is considered for this sector. You will see db 0x55, 0xaa. just 0x1fe + 2 = 0x200 = 512 bytes of running results will not be posted. Note: Most of the content in this article comes from the 30-day self-made operating system book. only some content and what you understand are recorded. errors are inevitable. Thank you! Address: http://www.cnblogs.com/icez/p/3963355.html
<30-day self-made operating system> (1) initial experience with Assembler