Write Your Own Operating System Tutorial(3) (轉)
In this lesson we will learn to use an assembler to write our programs. In previous lessons we have assembled them using DE. After playing around with this for a while, you will quickly see that it would be a pain to use DEBUG to create a program of more than a handful of instructions (even harder to modify). We need a simpler way. We will start by using thew Assembler” (NASM). Go to the official page at and a copy of the assembler.
Now we’ll use this assembler to create the same “operating system” that we did at the end of . Download the boot program and take a look at it. The first instruction should be somewhat familiar by now. This is the instruction to jump over the Boot Record data. In this case, it’s a jump to the label begin. After the jump instruction is 20 bytes of data. This is the data that I read off my floppy disk using the DEBUG program. These values should work fine. If you want, try replacing the data with the data from your own disk. Most of it should be the same.
(NOTE: Keep in mind that numbers made up of more than 1 byte will look “byte sped” when viewed in DEBUG because on the architecture, the least significant byte is stored at the lowest memory address and vice versa. The bytes will look backwards.)
The code starting at the label begin should look similar to the code we wrote for Lesson 2. It simply prints the letter ‘H’ to the screen and ls forever. At the bottom of this file you will see first a check to make sure the code all fits within 512 bytes (the size of one sector), then the line beginning with the “times” adds zerto the end of the file to pad the executable to 510 bytes. Finally, the two-byte signature 0x55, 0xAA is added to the end of the file. Assemble the file at the command prompt with the following command.
nasmw h.asm –o h.bin:namespace prefix = o ns = "urn:schemas--com::office" />
This assembles the assembly file to a pure binary executable h.bin. Check the size of the binary file. If we have done things right, it should be exactly 512 bytes. This is exactly the size needed to fit in the boot sector of the floppy.
Now we need to copy this file onto our floppy. With the floppy in the disk, run DEBUG, and type the following commands
debug
-n h.bin
-l 0
This loads our file into memory starting at address 0. Use the dump (d) and unassemble (u) commands if you wish to confithat our file has assembled and been loaded correctly. You will be able to see the few instructions that we have written. Notice that the file has been correctly padded with zeros up until bytes 0x1FE and 0x1FF at the end of the sector. Also note that DEBUG fills the CX register with the number of bytes loaded from the file. (Display the contents of the registers with the r command.)
With the floppy disk in the drive, write the file to the disk with the usual command.
-w 0 0 0 1
Reboot the computer with the floppy and see the program in action. Try some more things with the code, now. For example, maybe modify the code to print more characters. When you are ready, proceed to the next lesson where we will create a “Hello, World” operating system.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993853/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Write Your Own Operating System Tutorial(1) (轉)
- Write Your Own Operating System Tutorial(2) (轉)
- Write Your Own Operating System Tutorial(4) (轉)
- Write Your Own Operating System Tutorial(5) (轉)
- Write Your Own Operating System Tutorial(6) (轉)
- Write Your Own Operating System Tutorial(7) (轉)
- Write Your Own Operating System Tutorial(中文版) (轉)
- Write Your Own Operating System Tutorial(中文版) 簡介 (轉)
- Write Your Own Operating System Tutorial(中文版) 簡介
- Build Your Own Cas Service - ProUI
- operating-system structuresStruct
- Checking operating system version FailedAI
- Backup your Linux SystemLinux
- Checking operating system version Failed 續AI
- The Database Administrator's Operating System Account (25)Database
- Can one execute an operating system command from PL/SQL?SQL
- 【build your own xxx】實現你自己的bind函式UI函式
- mysql 啟動錯誤(InnoDB: Operating system error number 13 )MySqlError
- MYSQL-Operating System Error Codes(錯誤程式碼)MySqlError
- 【build your own xxx】實現你自己的call和applyUIAPP
- redhat your system appears to have shut down uncleanlyRedhatAPP
- 作業系統-Operating-System第一章:概述作業系統
- 安裝 ESXi 出現錯誤 ERROR 1962: No operating system foundError
- Protecting Your Database: Specifying Passwords for Users SYS and SYSTEM (70)Database
- 使用oracle的作業系統認證(Operating System Authentication)的方法Oracle作業系統
- Microsoft Agent Tutorial Chapter 1 (轉)ROSAPT
- Microsoft Agent Tutorial Chapter 2 (轉)ROSAPT
- Discover Your Missed ASM Disks(轉)ASM
- Linux安裝Oracle報Checking operating system version must be redhat-3, SuSE-9, redhat-4, UnitedLinux-1.0,LinuxOracleRedhat
- Write Video Based OpenCv3IDEOpenCV
- 【OEL】Oracle Enterprise Linux Operating System下載方法及安裝體驗OracleLinux
- Entity Framework Tutorial Basics(3):Entity Framework ArchitectureFramework
- Tutorial: Hello World with Ant(轉,來自apache)Apache
- She Got her ownGo
- 轉載:System:System.arraycopy方法詳解
- Python3.4 Tutorial9 - Classes (Part 3)Python
- Pytorch | Tutorial-03 資料轉換PyTorch
- Win10系統無法開機提示“error loading operating system”怎麼解決Win10Error