In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
This article comes from the official account of Wechat: low concurrency programming (ID:dibingfa). Author: flash.
The book follows last time, and last time we talked about CPU executing the first two lines of code of the operating system.
Mov ax,0x07c0mov ds,ax changes the value of the segment register ds to 0x07c0, making it easier to use this segment base address when accessing memory later.
Next, with these two lines of code, let's move on to a few lines.
Mov ax,0x07c0mov ds,axmov ax,0x9000mov es,axmov cx,#256sub si,sisub di,direp movw the value of the ds register is already 0x07c0, and then the value of the es register is changed to 0x9000 in the same way, and then the value of the cx register is changed to 256 (the code is indeed expressed in decimal, somewhat inconsistent with other places, but it doesn't matter).
Looking further down, there are two sub instructions, and this sub instruction is very simple, such as
Sub a _ r _ b means
A = a-b, then in the code
Sub si,si means
Si = si-si so if the two registers behind the sub are exactly the same, it is equivalent to zeroing the value in this register, which is a basic game.
That's very simple. After these instructions, the following registers are appended with the specified values. Let's comb through them.
Ds = 0x07c0
Es = 0x9000
Cx = 256
Si = 0
Di = 0
Remember the general picture of the CPU register drawn in the previous lecture? This is the way it is now.
Why attach values to these unrelated registers? In fact, it is for the next instruction, that is,
Rep movw where rep means to repeat the following instructions.
The following instruction movw means to copy a word (word 16-bit), which is to copy a word over and over again.
Then there are naturally three consecutive questions below:
How many times do you repeat the execution? Is the value in the cx register, that is, 256 times.
From where to where? Is copied from ds:si to es:di.
How much do you copy at a time? As I just said, copy one word, 16 bits, that's two bytes.
The way to translate this passage into more human language is to copy the 512 bytes of data starting from the memory address 0x7c00 to 0x90000 intact.
This is the second step in the picture below.
Yes, it was just a twist. Now, the code at the beginning of the operating system has been moved to the 0x90000 location.
And then there's a jump command.
Jmpi go,0x9000 mov ax,cs mov ds,ax, if you think about it, maybe you can guess what it wants.
Jmpi is an inter-segment jump instruction that means to jump to 0x9000:go for execution.
Remember the base address of the segment mentioned in the previous lecture: how to calculate the memory address in the format of offset address? The segment base address still needs to be moved four digits to the left first, so the conclusion is to jump to the memory address 0x90000 + go to execute. Forget to hurry back to have a look, this is only once, oh, to be steady.
In addition, go,go is a tag that will eventually be translated into a value when compiled into machine code, which is the offset address of the tag go in the file.
This offset address, plus 0x90000, happens to be the memory address of the code mov ax,cs behind the go tag.
So if the line of mov ax,cx is at the 0x08 of the final compiled binary, then go is equal to 0x08, and the final address where CPU jumps to is 0x90008.
So at this point, the content of the first two rounds is actually a piece of 512-byte code and data, first moved from the boot area of the hard disk to the memory 0x7c00, then immediately moved to the 0x90000, and then jumped here and then slightly offset the offset address represented by the go label, that is, the location of the mov ax,cs instruction line.
Still keep every time concise, this article ends here, I hope you can still keep up, the next time, we will focus on the go tag behind the code, see what he wants to toss.
The world behind is becoming more and more wonderful. If you want to know what happens in the future, let's listen to the decomposition next time.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.