1 Introducing a text editor
This section can be skipped directly
2 continued development
Helloos.nas before the core program content and ScanDisk outside of the content, because it also involves some floppy knowledge.
And then it's Helloos.nas the file.
;Hello-os;tab=4ORG 0x7c00;indicates the loading address of the program;The following section records a floppy disk in the FAT12 format JMPEntry DB 0x90 db"HELLOIPL" ;the name of the boot sector can be any string (8 bytes)Dw + ;the size of each sector (sector) (must be 512 bytes)Db1 ;the size of the cluster (cluster) (must be 512 bytes)Dw1 ;Start position of fat (typically starting with the first sector)Db2 ;number of fat (must be 2)Dw224 ;the size of the root directory (typically set to 224 items)Dw2880 ;the size of the disk (must be 2880 sectors)DB 0xf0;type of disk (must be 0xf0)Dw9 ;fat Length (must be 9 sectors)Dw - ;1 tracks (track) with several sectors (must be)Dw2 ;number of heads (must be 2)Dd0 ;do not use partitions, must be 0Dd2880 ;override disk Size onceDb0,0, 0x29;meaning unknown, fixedDD 0xFFFFFFFF;(may be) volume label numberDb"Hello-os" ;Name of the disk (11 bytes)Db"FAT12" ;disk format name (8 bytes)Resb - ;empty 18 bytes First;Program BodyEntry: MOVAx0 ;Initializing Registers MOVSs,axMOVsp,0x7c00MOVDs,axMOVEs,axMOVsi,msgPutloop: MOVAl,[si]ADDSI,1 ;add 1 to Si CMPAL,0 JEFinMOVah,0x0e;Display a text MOVBx the ;Specify character color INT0x10;calling the video card BIOS JMPPutloopFin: HLT ;let the CPU stop waiting for instructions JMPFin;Infinite Loopsmsg:DB 0x0a, 0x0a;2-Time line breakDb"Hello, World"DB 0x0a;line BreakDb0Resb 0x7dfe-$;fill in 0x00 until 0x7dfeDB 0x55, 0xaa;The following is an output from a section other than ScanDiskDB 0xf0, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00 resb4600DB 0xf0, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00 resb1469432
ORG directive
The org directive tells Nask where to load these machine language commands into memory at the beginning of execution.
This instruction also changes the meaning of $, no longer refers to the number of bytes in the output file, but rather represents the memory address that will be read in.
ORG is "origin", "source, start" meaning, it will tell Nask, the program to start from the specified address that is to load the program into memory of the specified address.
JMP,JE directive
Equivalent to the Goto label in C, we have been educated for many years not to Goto ...
The "JMP entry" command is a program that allows the CPU to execute memory addresses at entry.
Label
In the above program, both Entry,fin,putloop and MSG are labels, which are equivalent to an entry address, or tag.
The number corresponding to each label is calculated by the assembly language compiler according to the org instructions. The compiler calculates the "number of places corresponding to the memory address" is the value of that label.
MOV instructions
Various registers in the CPU
compilation [] Value
mov al, si means to pass the value of the SI register to the AL register, but mov al, [si] means to store a number in SI, and this number represents an address in memory, [SI] means to take out the value of this address.
MOV BYTE [678], 123
MOV WORD [678], 123
Problem with data size end
int directive
int is a software interrupt instruction. This means interrupting the current execution path of the CPU and running to other places to execute.
The BIOS stores a collection of various functions prepared for the developer, and the numbers that are not connected to the int instruction call the corresponding function in the BIOS.
HLT directive
HLT let the CPU stop the action instructions, but not a complete stop, but to let the CPU standby state, as long as the external changes, such as the mouse keyboard, will wake up, continue to execute the program.
Without the HLT instructions, the CPU will continue to execute only the JMP instructions, with a load of 100% and a very power charge.
0x7c00
Now the memory address is very big, and the memory price of this year is very bad.
The No. 0 address of memory, which is the first place, is where the BIOS program is used to achieve a variety of functions, and if used casually it will conflict with the BIOS.
Additionally, the BIOS program itself is stored near the 0xf0000 address of the memory and cannot be used.
Memory is also not available in many places, as operating system developers should pay special attention.
0X00007C00~0X00007DFF: Loading address of ScanDisk content
The org directive in the program refers to this address.
I didn't explain why it was 0x7c00, and I found it on the Internet.
The content comes from Nanyi teacher Blog
=================== start_1 =======================
The computer principles textbook says that the master boot record is stored in memory address 0x7c00 at startup.
This strange address, how to come, the textbook will not explain. I have always wondered, why not put in the memory of the head, tail, or other location, and just deposit this 1024 bytes smaller than 32KB place?
Yesterday, I read an article, finally solved the mystery.
First of all, if you don't know what the Master boot record (Master boot record, abbreviated as MBR) is, you can read first how does the computer start? 》。
Simply put, computer startup is such a process.
- Power
- Read the BIOS inside the ROM to check the hardware
- Hardware check through
- The BIOS checks the first sector of the boot device (that is, the master boot record) according to the specified order, loading the memory address 0x7c00
- Master boot Record give operation right to operating system
Therefore, the master boot Record is a small program that directs the "operating system" into memory, with a size of no more than 1 sectors (512 bytes).
0X7C00 This address comes from Intel's first-generation PC chip 8088, which is used by future CPUs to stay compliant.
IBM's first PC, IBM PC 5150, went public in August 1981, using the chip.
At that time, the operating system was 86-dos. The minimum memory required for this operating system is 32KB. We know that the memory address is numbered from 0x0000, and that 32KB of memory is 0X0000~0X7FFF.
The 8088 chip itself needs to occupy 0X0000~0X03FF, which is used to store the various interrupt handlers. ( the master boot record itself is a handler for interrupt signal int 19h .) So, the memory is only left 0X0400~0X7FFF to use.
To leave as much contiguous memory as possible to the operating system, the master boot record is placed at the tail end of the memory address. Since a sector is 512 bytes, the master boot record itself produces data that requires an additional 512 bytes to be saved. So, its reserved position becomes:
0x7fff-512-512 + 1 = 0x7c00
That's how 0x7c00 came.
After the computer starts, 32KB memory is used as follows.
=================== end_1 =======================
Appreciate the feelings of the teacher Ruan's digging in the end
So in fact ScanDisk put to 0x7c00 position, less than 32KB 1KB, remember this, then put a B.
3 Start-up area is first created
Here the author said that do not want to use nask to make the entire disk image, but first use it to make the boot area, remove the second half, the program also renamed to Ipl.nas.
Probably this section of the content is removed, is only left to the second AA, remember 55AA, the first sector of the last two bytes oh.
4 Makefile Getting Started
This is not to say, is to have to manually input the compilation command written makefile this file.
Can data be executed?
What the CPU executes is, the instruction, the instruction is the data, the CPU first look for the instruction, then find the operand. You can do it for a cpu,cpu of data.
What this means is, the blind to the CPU to pass instructions and data, the results of the CPU execution pit is also a mess.
30-Day Homemade operating System (ii) Assembly language learning and makefile introduction