حسنا. لذلك هو يوم ربيع جميل ، هنا ، في الحرم الجامعي. أنا سأعمل سجل
في الخارج ، هنا في حرم ستانفورد. مجرد نوع من مشمس ، مثل حديقة ، مليئة الكلية
الطلاب مجرد نوع من مثل ، شنقا. لذلك
موضوع هذا القسم هو: ما هو البرنامج؟ ما هو الكود؟ كيف ذلك
شيء يعمل على الكمبيوتر؟ لذلك عندما تحدثنا عن الأجهزة في الكمبيوتر نحن
تحدثت عن وحدة المعالجة المركزية ، وهذا هو أدمغة الشيء. لذلك وحدة المعالجة المركزية ما يفعله في الواقع
قيد التشغيل ، وينفذ وحدة المعالجة المركزية ما يسمى "تعليمات رمز الجهاز". و
تعليمات رمز الجهاز بسيطة للغاية. تعليمات رمز آلة واحدة قد
إضافة رقمين ، قد يقارن تعليم آخر رقمين لمعرفة أي رقم
أكبر. لذلك ، عندما ، للحصول على الكود الذي رأيناه ، فإن شيئًا مثل البكسل يعين النقطة الحمراء عشرة.
هذا أكثر تعقيدًا بكثير من تعليمات رمز الجهاز الفردي. وبالتالي
الطريقة التي ستعمل بها ، هي أن بكسل تعيين النقطة الحمراء عشرة سوف في نهاية المطاف
توسيع إلى سلسلة من خمسة أو عشرة من هذه التعليمات البرمجية آلة بسيطة للغاية
تعليمات ، بحيث ، عندما يتم تشغيل تلك التعليمات العشر ، واحدة تلو الأخرى ،
له نوع من تأثير تعيين القيمة الحمراء للبكسل إلى عشرة. حسنا ، و
سأخوض في مزيد من التفاصيل لاحقًا حول ، كيف ، كيف يحدث هذا التوسع. وبالتالي،
أعتقد أن السؤال الأول الجيد لإدارة البرنامج يشبه ، حسناً ، ما هو
برنامج؟ لذلك سوف ننظر إلى ، الجانب الأيمن من هذا
رسم بياني. لذلك برنامج - وأنا ، سأكون نوع من الاستخدام ، كمثال على التوالي ،
فايرفوكس - لذلك يتكون البرنامج في الواقع من مجرد تسلسل هائل من هذه جدا
تعليمات رمز الجهاز بسيطة. وهكذا ، عندما يكون Firefox ، يعمل على جهازك
الكمبيوتر ، وهذا يعني في مكان ما في RAM ، هناك كتلة من هذه التعليمات ،
إن تشغيلها ، كما تعلم ، يفعل الأشياء التي يقوم بها Firefox. لذلك
يومض المؤشر ، ويستغرق عنوان URL ورسمه ويحصل على صفحات الويب وكل هذه الأشياء.
لذا ، فإن التعليمات الفردية تافهة حقا ، أليس كذلك؟ فقط أضف رقمين. وبالتالي
كيف يمكن الحصول على ذلك من مثل وضع وميض المؤشر؟ وأفضل ما يمكنني قوله هو أنه
ربما نوع من مثل العلاقة بين الرمال والنحت. أن كل
التعليمات هي مثل حبة الرمل. مثل في حد ذاته لا معنى له وأنه نوع من
يشبه كل الآخرين. لكن إذا جمعتهم معًا بالطريقة الصحيحة ،
يمكن بناء هذا الهيكل الشامل المعقد. وهذه هي الطريقة التي
All right. So it's such a beautiful spring day, here, on campus. I'm gonna record
outside, here at Stanford campus. Just kind of sunny, park like, filled with college
students just kind of like, hanging out. So the
topic for this section is: What is software? What is code? How is it that
something runs on a computer? So when we talked about hardware in the computer we
talked about the cpu, that's the brains of the thing. So the cpu's what actually does
running, and the cpu implements what is called "machine code instructions". And
machine code instructions are extremely simple. One machine code instruction might
add two numbers, another instruction might compare two numbers to see which one is
bigger. So, when, for code that we've seen, so something like pixel set red dot ten.
That's much more complicated, than an individual machine code instruction. So
the way that's going to work, is that pixel set red dot ten will ultimately
expand to a series of maybe five or ten of these very simple machine code
instructions, such that, when those ten instructions are run, one after the other,
it sort of has the effect of setting the red value of the pixel to ten. Alright, and
I'll get into more detail later on about, how that, how that expansion happens. So,
I think a good first question for running a program is like, alright well, what is a
program? So I'll look at the, the right hand side of this
diagram. So a program - and I'll, I'll sort of use, as my running example,
Firefox - so a program is made actually of just an enormous sequence of these very
simple machine code instructions. And so, when Firefox is, is running on your
computer, that means somewhere in RAM, there's a block of these instructions,
such that running them, has, you know, does the things that Firefox does. So it
blinks the cursor, it takes URL, draws, gets web pages and all that sort of stuff.
So, the individual instructions are really trivial, right? Just add two numbers. So
how does it get from that to like blinking the cursor? And the best I can say is it's
maybe sort of like the relationship between sand and sculpture. That each
instruction is like a grain of sand. Like by itself it's meaningless and it kind of
looks like all the others. But if you put them together in just the right way, you
can build this complicated overall structure. And so that is the way that
تم بناء Firefox من هذه ، هذه التعليمات البسيطة. وبالتالي الطريقة التي يعمل بها
هو وحدة المعالجة المركزية ، هنا على اليسار ، تدير ما يسمى دورة تنفيذ الجلب. و
كل هذا يعني أن وحدة المعالجة المركزية ستبدأ ، دعنا نقول هنا ، مع التعليمات واحد ،
وسوف تحميل هذا التعليمات وتشغيله. أو في بعض الأحيان سنقول أنه ينفذ
هذا التعليم. لذلك ، فإنه يضيف الرقمين ، أو يفعل أي شيء
يقول التعليمات. وعندما يتم ذلك ، يتم ذلك باستخدام "التعليمات الأولى" ، إنه ينخفض
القائمة. يذهب إلى التعليمات الثانية ، ويفعل ذلك. يذهب إلى التعليمات الثلاثة ،
ويفعل ذلك واحد ، وهلم جرا. فقط
يمر عبر التسلسل. لذلك ، عندما نقول أن وحدة المعالجة المركزية تعمل في اثنين جيجاهيرتز ، اثنان
مليار عملية في الثانية الواحدة ، هذه هي التعليمات البسيطة التي تشير إلى.
لذلك ، من الواضح أن هناك مجموعة كبيرة ومتنوعة من التعليمات. لكن أنا فقط
سوف نشير إلى أنواع خاصة زوجين. لذلك هناك نوع واحد من التعليمات له تأثير
تغيير الترتيب الذي التعليمات. عادة وحدة المعالجة المركزية فقط يعمل أسفل القائمة
وهل لهم بالترتيب. ولكن دعنا نقول تعليمات أربعة ربما يقول ، يا القفز مرة أخرى
والبدء في تنفيذ مرة أخرى في تعليمات واحدة. وحتى التفكير في ما وحدة المعالجة المركزية
سافعل. لذلك ستعمل التعليمات ... واحد ، اثنان ، ثلاثة ، أربعة. وبعد ذلك عندما
يحصل على أربعة ، وسوف قفز إلى الوراء ، وتعليمات واحد ، اثنان ، ثلاثة مرة أخرى. و
ثم واحد ، اثنان ، ثلاثة مرة أخرى ، ومرة أخرى. يمكنك أن ترى kinda كيف هي الحلقات
تنفيذها. مجرد ترتيب التعليمات بحيث يكون هناك قطعة
من كود نريد أن نفعل 500000 مرة. حسنًا ، يمكنك إعداد تعليمات للحلقة فقط
مرارًا وتكرارًا ، قم بهذه الإرشادات مرارًا وتكرارًا. نوع آخر من التعليمات ،
أو فكرة ذات صلة ، هي تعليمات ، حسنا ، نفس التعليمات اثنين هنا ، والتي
يختبر بعض الحالات وإذا كانت الحالة صحيحة ، فربما يتخطى ذلك إلى أين
تعليمات خمسة سيكون هنا. وبالتالي. هذا كيف لو تم تنفيذ البيانات. أنت
لديك تعليمات هذا سوف ننظر إلى بعض الشرط ، وإذا كان ، إذا
Firefox is built out of these, these simple instructions. So the way it works
is the CPU, over here on the left, runs what is called a fetch execute cycle. And
all that means is that, the CPU will start off, let's say here, with Instruction one,
and it'll load that instruction and run it. Or sometimes we'll say it executes
that instruction. So, it, it adds the two numbers, or it does whatever the
instruction says. And when it, it's done with Instruction one, it just goes down
the list. It goes to Instruction two, and it does that one. It goes to instruction three,
and it does that one, and so on. It just
runs through the sequence. So, when we say that a CPU operates at two gigahertz, two
billion operations per second, it's these little instructions that that refers to.
So there are, there's obviously a, a big variety of instructions. But I'm just
gonna point out a couple special types. So one type of instruction has the effect of
changing the order that the instruction. Normally the CPU just runs down the list
and does them in order. But let's say instruction four maybe says, oh jump back
and start executing again at instruction one. And so think about what the cpu's
gonna do. So it's gonna do instructions... One, two, three, four. And then when it
gets to four, it'll sorta jump back, and do instructions one, two, three again. And
then one, two, three again, and again. You can sorta see that's how loops are
implemented. Just arranging the instructions so that there's some piece
of code we wanna do 500,000 times. Well, you can set up an instruction to just loop
back and so, do those instructions again and again. Another sort of instruction,
or a related idea, is an instruction, well, the same instruction two here, which
tests some condition and if the condition is true maybe it skips ahead, to where
instruction five would be here. So. That's how if statements are implemented. You
have an instruction that's gonna look at some condition, and if it's, if the
الشرط صحيح ، سأخبر وحدة المعالجة المركزية بالانتقال إلى هنا. وإذا كان كذلك
خطأ ، سوف ينتقل إلى مكان آخر. لذلك عن طريق ترتيب التعليمات فقط ،
يمكنك الحصول على تأثير ، شيء يبدو أننا ، في التعليمات البرمجية الخاصة بنا ، يبدو وكأنه علامة if
بيان. Alrighty. فكيف ، كيف يتم تشغيل البرنامج و
كيف نصل إلى ، كيف نصل إلى هذه الحالة؟ لذلك أتصور أنك حصلت ،
فايرفوكس على محرك فلاش ، كما تعلمون ، الملف. حتى على محرك فلاش الخاص بك ، أو على
قرص صلب. لذا ، لقد قمت بالتخزين على المدى الطويل ، كما تعلمون ، التخزين المستمر باستمرار
هنا. وهنا ذاكرة الوصول العشوائي وهنا وحدة المعالجة المركزية. لذلك عندما يكون لديك فايرفوكس على الثابت الخاص بك
محرك الأقراص ، ملف ، في الأساس ، وهنا أنا ، يطلق عليه Firefox exe ، هذا هو
مجرد اتفاقية Windows ، لمعرفة كيفية تسمية ملف ، وهو برنامج ، لكن ،
إنه يساعد على إبقاء الأمور أكثر وضوحًا لذا سأتابع ذلك. لذلك firefox.exe ، هذا الملف ، ذلك
يحتوي على الكثير من البايتات فيه ، وفي الغالب ، تلك البايتات ، هي فقط البايتات
الإرشادات التي تشكل البرنامج ، بالإضافة إلى بعض الرموز والصور وغيرها
أمور. إذن ما أريد التفكير فيه جيد ، ماذا يحدث عند النقر المزدوج
FIREFOX.EXE؟ كيف يبدأ الركض؟ وما يحدث هو وجود اثنين
خطوات. أول ما يحدث هو البايت لهذه التعليمات ، على الأقل
يكفي من التعليمات للبدء ، احصل على نسخ تصل إلى RAM. لذلك فقط نسخ ،
يضع التعليمات في ذاكرة الوصول العشوائي حيث يمكن الحصول على وحدة المعالجة المركزية عليها. ثم الخطوة الثانية ، فقط
أخبر وحدة المعالجة المركزية ، "حسنا ، حسنا ، هنا تعليمات واحدة. ابدأ بالتنفيذ هنا.
وهكذا ، تبدأ وحدة المعالجة المركزية فقط في نسخ سلسلة التعليمات الآن
إنه يشغل Firefox. لذلك أعتقد أن هذا يؤدي إلى مسألة مثل ، حسنا انتظر من
هل هذا صحيح؟ كيف فعلت - الذي يعالج
انقر نقرا مزدوجا؟ من الذي يقوم بتشغيل Firefox؟ وهذا هو ما التشغيل
النظام هو. لذلك نظام التشغيل هو مجموعة من أنواع الإشراف و
برامج إدارية من هذا النوع ، كما تعلمون ، تنظم وتنظم النظام بأكمله.
لذلك ، على وجه الخصوص ، يدير نظام التشغيل برامج متعددة ، ويبدأ
و ، إنهاء البرامج. لذلك يمكن للكمبيوتر الحديث تشغيل برامج متعددة في نفس الوقت
الوقت وحتى نظام التشغيل sorta يبقي الأشياء المنظمة. لذلك ، فإنه يفعل
بدء التشغيل الأولي للبرنامج ، وإعطائه بعض ذاكرة الوصول العشوائي للاستخدام ، وربما إعطائه
نافذة للرسم. أيضًا ، تحاول أنظمة التشغيل إبقاء البرامج معزولة عن بعضها
آخر. لذلك كل برنامج لديه ذاكرة الوصول العشوائي الخاصة به ، ولكن لا يمكن بالضرورة أن يذهب مع الفوضى
ذاكرة الوصول العشوائي من بعض البرامج الأخرى. بحيث يساعد إذا كان البرنامج لديه البق. نأمل ، سوف
مجرد خبط هذا البرنامج ، ولكن لا خبط بعض البرامج الأخرى التي تقوم بتشغيلها. أو
بشكل ضار ، إذا كنت أحاول أن أفعل شيئًا سيئًا لبعض البرامج الأخرى ،
يحاول نظام التشغيل الاحتفاظ بها منفصلة. لذلك ، نظام التشغيل هو
حقا أول شيء يعمل عند بدء تشغيل جهاز الكمبيوتر الخاص بك. هذا ما سيحدث
ضع تلك النوافذ الأولى ، وربما اعرض لك ما يوجد على القرص الصلب. وثم،
من بعد ذلك ، يمكنك النقر نقرًا مزدوجًا أو القيام بأشياء أخرى ونظام التشغيل
سوف تبدأ تلك البرامج لك. هذا هو حقا ، الشيء الذي أنت عليه
رؤية ، عند بدء تشغيل جهاز الكمبيوتر المحمول. الكاميرا الرقمية ، ذلك ، أنت لا تفكر في ذلك
كجهاز كمبيوتر ، بالضرورة ، لكنه في الحقيقة نفسه. عندما تكون الكاميرا الرقمية
يبدأ لأول مرة ، وربما هناك برامج زوجين. ربما هناك البرنامج الذي
يلتقط الصور ، والبرنامج الذي يتيح لك الاطلاع على الصور التي لديك
مأخوذة. وهكذا ، عندما تبدأ الكاميرا لأول مرة ، هناك القليل منها
إداري، حصل على شيء ما، احصل على البرامج التي تعمل على إظهار نوع ما
واجهة ، وبعد ذلك فقط يتيح لك الذهاب. صباحا. لذلك ، كشيء أخير ، هناك
نوع من ، و ، هذه ، هذه المصطلحات التمهيد وإعادة التشغيل ، اعتقدت دائما أنه كان
مضحك كيندا. مثل ، من أين يأتي هذا؟ وأنا ، يشير إلى هذا النوع من
مشكلة بيضة دجاج ، مثل ، حسنا ، عندما يتم تشغيل الكمبيوتر لأول مرة ، عندما لأول مرة
يبدأ ، كيف يفعل ذلك. كيف تحصل على نفسها المنظمة؟ كيف تبدأ؟
تشغيل البرنامج؟ وهذه المصطلحات تأتي في الواقع من نوع من نكتة قديمة ،
حول ما إذا كنت ترغب في الحصول على سياج ، ما يمكنك القيام به هو الوصول إلى
bootstraps الخاص بك ، وسحب ما يصل ، تماما مثل رفع نفسك على السياج ذلك
الطريقة. ومن الواضح أنه نوع من العبث. ولكن ، لديها نفس الجودة مثل ،
انتظر جيدًا ، ما البرنامج الذي يعمل عليه الكمبيوتر لتمكين الكمبيوتر من التشغيل
البرامج. لذلك هو نوع من مشكلة الدجاج والبيض. لذا الطريقة التي تعمل بها هي أن
الأجهزة ، وحدة المعالجة المركزية ، لديها ، عندما تدرك أن لديها ، تم إيقاف تشغيله ،
وأن لديها ، لقد بدأت للتو. وهكذا هناك برنامج صغير خاص
هو سلك صلب في الكمبيوتر لتشغيل ، في تلك اللحظة. وهذا البرنامج يمكن ربما
تحقق ، تحقق من منطقة الأجهزة ، كما تعلمون ، قم ببعض الأشياء الأساسية لبدء التشغيل المبكر.
وبعد ذلك يتطلع إلى حد كبير إلى قرص ثابت أو محرك أقراص محمول أو شيء ما
يحتوي على نظام تشغيل عليه. وبعد ذلك يمكن أن تبدأ التشغيل
النظام ثم ، ثم يمكن للكمبيوتر بدء التشغيل بهذه الطريقة.
condition is true, it's gonna sort of tell the CPU to go over here. And if it's
false, it'll go over to some other place. So by arranging the instructions just so,
you can get the effect of, something that we, that, in our code, looks like an if
statement. Alrighty. So how, how does a program get running and
how do we get to, how do we get to this state? So I would imagine you've got,
Firefox on your flash drive, you know, the file. So on your flash drive, or on your
hard drive. So here, I've stored, long term, you know, persistent storage down
here. And here's RAM and here's the CPU. So when you've got Firefox on your hard
drive, it's a file, basically, and here I, it's called Firefox exe, that's
just a Windows convention, for, how to name a file, which is a program, but it,
it helps keep things clearer so I'll follow that. So firefox.exe, that file, it
has a lot of bytes in it, and for the most part, those bytes, are just the
instructions that make up the program, plus some icons, pictures and other
stuff. So what I want to think about is well, what happens when you double click
Firefox.exe? How does it start running? And basically what happens is there's two
steps. The first thing that happens is the bytes for these instructions, at least
enough of the instructions to get started, get copied up to RAM. So it just copies,
puts the instructions in RAM where the CPU can get at them. And then step two, just
tell the CPU, 'Okay, well, here's instruction one. Start executing here.'
And so then the CPU just starts ripping down the series of instructions and now
it's running Firefox. So I think this leads to the question of like, well wait who
do this, right? How did - who handles
the double click? Who gets Firefox running? And so that's what an operating
system is. So the operating system is a set of kind of supervisory and
administrative programs that sort of, you know, organize, organizes the whole system.
So, in particular, the operating system manages multiple programs, and starting
and, ending programs. So a modern computer can, run multiple programs at the same
time and so the operating system sorta keeps things organized. So it, it does the
initial startup of a program, giving it some RAM to use, and maybe giving it a
window to draw in. Also, operating systems try to keep programs isolated from each
other. So each program has its RAM, but it can't necessarily just go mess with the
RAM of some other program. So that helps if a program has bugs. Hopefully, it'll
just mess up that program, but not mess up some other program that you're running. Or
maliciously, if I program was trying to do something bad to some other program that,
the operating system tries to keep them separate. So, the operating system is
really the first thing that runs when your computer starts up. So that's what's gonna
put up those first windows, and maybe show you what's on the hard drive. And then,
from thereafter, you can double click, or do other things, and the operating system
will start those programs for you. So that's really the, the thing you're
seeing, when you start up your laptop. Digital camera, it, you don't think of it
as a computer, necessarily, but it's really the same. When the digital camera
first starts up, there's probably a couple programs. There's maybe the program that
takes pictures, and the program that lets you look through the pictures you've
already taken. And so, when the camera first starts out, there's a little bit of
administrative, sorta get, get the, the programs running to sort of show you the
interface, and then it just lets you go. Am. So just as a, a last thing, there's
sort of the, the, these, this terminology boot and reboot, I always thought that was
kinda funny. Like, where does that come from? And I-, it refers to the sort of
chicken egg problem of, like, well, when the computer first turns on, when it first
starts up, how does it. How does it get itself organized? How does it start
running a program? And this terminology actually comes from sort of an old joke,
about if you want to get over a fence, what you could just do is reach down to
your bootstraps, and pull up, and just like lift yourself over the fence that
way. And it's obviously kind of absurd. But it, it has the same quality of like,
well wait, what program does the computer run to enable the computer to run
programs. So it sort of a chicken and egg problem. So the way it works is that the
hardware, the, the CPU, has, when it recognizes that it has, it was turned off,
and that it has, it has just started up. And so there's a special tiny program that
is hardwired into the computer to run, at that moment. And that program can maybe
check, check what's hardware area, you know, do some basic early start-up stuff.
And then pretty much it looks around for a hard disk or a flash drive or something
that contains an operating system on it. And then it can start that operating
system and then, then the computer can start up in that way.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
البرمجيات
البرنامج - الرمز الذي يعمل على الأجهزة
سأبسط الأمور هنا قليلاً
تنفذ وحدة المعالجة المركزية تعليمات "كود الآلة"
- كل تعليمات رمز الجهاز بسيط للغاية
--e.g. إضافة 2 أرقام
--e.g. مقارنة 2 أرقام
رمز رأينا
pixel.setRed (10)
- لتشغيل ، توسعت إلى حوالي 10 تعليمات رمز الجهاز
كود الآلة
"البرامج" هي الفئة العامة للرمز الذي يتم تشغيله على الجهاز. إذا كان الجهاز عبارة عن بيانو لاعب ، فسيكون البرنامج هو الموسيقى. الحالة الشائعة هي "برنامج" مثل Firefox - برنامج تقوم بتشغيله على جهاز الكمبيوتر الخاص بك لحل مشكلة معينة. يمكن لجهاز الكمبيوتر تشغيل برامج متعددة في نفس الوقت ، مع الحفاظ على استخدامهم للذاكرة ، والرسم في النوافذ ، وما إلى ذلك ، بحيث لا تتداخل مع بعضهم البعض.
تتفهم وحدة المعالجة المركزية لغة "كود الآلة" ذات المستوى المنخفض (المعروف أيضًا باسم "الكود الأصلي"). لغة كود الآلة متشابكة في تصميم أجهزة وحدة المعالجة المركزية ؛ إنه ليس شيئًا يمكن تغييره حسب الرغبة. كل عائلة من وحدات المعالجة المركزية المتوافقة (على سبيل المثال عائلة إنتل x86 المشهورة جدًا) لديها كود الآلة الخاص بها الذي لا يتوافق مع رمز الآلة لعائلات وحدة المعالجة المركزية الأخرى.
التعليمات والبرامج
يحدد كود الآلة مجموعة من التعليمات الفردية. كل تعليمات رمز الجهاز بدائية للغاية ، مثل إضافة رقمين أو اختبار إذا كان الرقم يساوي الصفر. عند التخزين ، يستغرق كل تعليمة بضع بايتات فقط. عندما قلنا سابقًا أن وحدة المعالجة المركزية يمكنها تنفيذ ملياري عملية في الثانية ، تشير "العمليات" إلى هذه التعليمات البسيطة لرمز الجهاز.
يتكون البرنامج ، مثل Firefox ، من سلسلة من ملايين التعليمات البرمجية البسيطة للغاية. من الصعب بعض الشيء تصديق أن شيئًا غنيًا ومعقدًا مثل Firefox يمكن بناؤه بناءً على تعليمات تضيف أو تقارن رقمين فقط ، ولكن هكذا تعمل. يمكن أن يكون التمثال الرملي غنيًا ومعقدًا عند النظر إليه من مسافة بعيدة ، على الرغم من أن حبيبات الرمال الفردية بسيطة للغاية.
ما هو البرنامج؟ ، ما هو قيد التشغيل؟
"البرنامج" على سبيل المثال Firefox ، ملايين التعليمات البرمجية البسيطة
- تعليمات ، مثل حبيبات الرمل التي تشكل النحت
وحدة المعالجة المركزية تدير "دورة جلب / تنفيذ"
- جلب تعليمات واحدة في التسلسل
- تنفيذ (تشغيل) هذه التعليمات ، على سبيل المثال هل الإضافة
- جلب التعليمات التالية ، وهلم جرا
تعليمات "حلقة": القفز 10 تعليمات
- يتم تنفيذ الحلقات بهذه الطريقة
تعليمات "إذا": تخطي إلى الأمام إذا كان هناك شرط معين صحيح
- إذا تم تنفيذ البيانات بهذه الطريقة
تقوم وحدة المعالجة المركزية بتشغيل الإرشادات باستخدام دورة "جلب الجلب": تحصل وحدة المعالجة المركزية على أول تعليمة في التسلسل ، وتنفذها (إضافة رقمين أو أي شيء آخر) ، ثم تجلب التعليمة التالية وتنفذها ، وهكذا. تؤثر بعض الإرشادات على الترتيب الذي تأخذ به وحدة المعالجة المركزية (CPU) في تسلسل التعليمات .. على سبيل المثال ، قد توجه التعليمات وحدة المعالجة المركزية للانتقال إلى نقطة سابقة في تسلسل التعليمات (يتم تنفيذ الحلقات بهذه الطريقة) ، أو لتخطي التالي التعليمات إذا كانت هناك حالة معينة صحيحة (إذا تم تنفيذ-if العبارات بهذه الطريقة).
وحدة المعالجة المركزية تدير سلسلة من تعليمات لغة الآلة
انقر مرتين على البرنامج
ما هو البرنامج ، مثل Firefox.exe (.exe هو اتفاقية Windows)
الملف Firefox.exe هو في الغالب بايت ملايين التعليمات
انقر نقرًا مزدوجًا فوق Firefox.exe للتشغيل
- يتم نسخ بايتات التعليمات في ذاكرة الوصول العشوائي
- يتم توجيه وحدة المعالجة المركزية لبدء التشغيل في التعليمات الأولى
قم بتشغيل Firefox.exe: (1) قم بنسخ التعليمات إلى RAM ، (2) تقوم وحدة المعالجة المركزية بتشغيلها
في نظام الملفات ، يحتوي ملف مثل Firefox.exe فقط على وحدات البايت الخاصة بتعليمات رمز الجهاز التي تشكل البرنامج (".exe" عبارة عن اصطلاح windows لوضع علامة على ملف كبرنامج). يستغرق كل تعليمة برمجية للجهاز حوالي 4 بايت ، ويعتبر البرنامج بالكامل مجرد تسلسل هائل من التعليمات.
يبلغ حجم Firefox 80 ميجابايت على الجهاز الخاص بي. على افتراض أن كل هذه البايتات هي إرشادات ، ولكل إرشادات 4 بايت ، كم عدد تعليمات كود الآلة التي تشكل Firefox؟ (الإجابة: 80 ميغابايت هي 80 مليون بايت ، بحيث يكون 20 مليون تعليمات.)
عندما ينقر المستخدم مرتين على ملف برنامج لتشغيله ، يتم نسخ كتلة بايتات التعليمات الخاصة بالبرنامج في ذاكرة الوصول العشوائي ، ثم يتم توجيه وحدة المعالجة المركزية لبدء التشغيل عند التعليمة الأولى في منطقة ذاكرة الوصول العشوائي هذه.
نظام التشغيل
Software
Software - code that runs on the hardware
I'm going to simplify things a bit here
CPU implements "machine code" instructions
--Each machine code instruction is extremely simple
--e.g. add 2 numbers
--e.g. compare 2 numbers
Code we have seen
pixel.setRed(10)
--To run, expanded to about 10 machine code instructions
Machine Code
"Software" is the general category of code which runs on the hardware. If the hardware is a player piano, then the software is the music. The common case is a "program" like Firefox -- software you run on your computer to solve a particular problem. A computer can run multiple programs at the same time, keeping their use of memory, drawing in windows etc. separated so they hopefully do not interfere with each other.
A CPU understands a low level "machine code" language (also known as "native code"). The language of the machine code is hardwired into the design of the CPU hardware; it is not something that can be changed at will. Each family of compatible CPUs (e.g. the very popular Intel x86 family) has its own, idiosyncratic machine code which is not compatible with the machine code of other CPU families.
Instructions and Programs
The machine code defines a set of individual instructions. Each machine code instruction is extremely primitive, such as adding two numbers or testing if a number is equal to zero. When stored, each instruction takes up just a few bytes. When we said earlier that a CPU can execute 2 billion operations per second, "operations" there refers to these simple machine code instructions.
A program, such as Firefox, is made up of a sequence of millions of these very simple machine code instructions. It's a little hard to believe that something as rich and complicated as Firefox can be built up out of instructions that just add or compare two numbers, but that is how it works. A sand sculpture can be rich and complicated when viewed from a distance, even though the individual grains of sand are extremely simple.
What is a Program?, What is Running?
"Program" e.g. Firefox, millions of simple machine code instructions
--Instructions, like grains of sand making up sculpture
CPU runs a "fetch/execute cycle"
--fetch one instruction in sequence
--execute (run) that instruction, e.g. do the addition
--fetch the next instruction, and so on
"loop" instruction: jump back 10 instructions
--Loops are implemented this way
"if" instruction: skip ahead if a certain condition is true
--If statements are implemented this way
The CPU runs instructions using a "fetch-execute" cycle: the CPU gets the first instruction in the sequence, executes it (adding two numbers or whatever), then fetches the next instruction and executes it, and so on. Some of the instructions affect the order that the CPU takes through the instruction sequence .. for example an instruction might direct the CPU to jump back to an earlier point in the instruction sequence (loops are implemented this way), or to skip over the next instruction if a particular condition is true (if-statements are implemented this way).
CPU runs a series of machine language instructions
Double Click a Program
What is a program, like Firefox.exe (.exe is a Windows convention)
The file Firefox.exe is mostly the bytes of millions of instructions
Double click Firefox.exe to Run
--The instruction bytes are copied up into RAM
--The CPU is directed to start running at the first instruction
Run Firefox.exe: (1) copy instructions to RAM, (2) CPU runs them
In the file system, a file like Firefox.exe just contains the bytes of the machine code instructions that make up the program (".exe" is a windows convention to mark a file as a program). Each machine code instruction takes up about 4 bytes, and whole program is just an enormous sequence of instructions.
On my machine, Firefox is 80 MB in size. Assuming all those bytes are instructions, and each instruction is 4 bytes, how many machine code instructions make up Firefox? (Answer: 80 MB is 80 million bytes, so that would be 20 million instructions.)
When the user double clicks a program file to run it, essentially the block of bytes of the instructions for the program are copied into RAM, and then the CPU is directed to begin running at the first instruction in that area of RAM.
Operating System
نظام التشغيل
من يبدأ فايرفوكس؟
نظام التشغيل
مجموعة من البرامج الإشرافية ، يتم تشغيلها عند بدء تشغيل الكمبيوتر لأول مرة
الإدارة وراء الكواليس
بدء / إدارة / إنهاء البرامج الأخرى
- يمكن لأجهزة الكمبيوتر الحديثة تشغيل برامج متعددة في نفس الوقت
- نظام التشغيل يحافظ على تشغيل كل برنامج معزولة
- يحتوي البرنامج على ذاكرة الوصول العشوائي الخاصة به ، والنوافذ الخاصة به على الشاشة
--ضد. عمل عرضي أو ضار بين البرامج
مثلا حاسوب محمول
مثلا كاميرا رقمية
يشبه "نظام التشغيل" لجهاز الكمبيوتر البرنامج الإشرافي الأول الذي يبدأ تشغيله عند بدء تشغيل الكمبيوتر لأول مرة ("بدء التشغيل"). يلعب نظام التشغيل دورًا غير مرئي للإدارة ومسك الدفاتر وراء الكواليس. عند بدء تشغيل سطح مكتب أو كمبيوتر محمول ، يقوم نظام التشغيل عادةً بتنظيم الأشياء ثم يقوم بتشغيل برنامج "مستكشف الملفات" الذي يعرض النوافذ والقوائم وما إلى ذلك يُظهر للمستخدم أنظمة الملفات المتاحة ، مما يتيح للمستخدم التنقل والعمل على الملفات.
يحتفظ نظام التشغيل بالأشياء منظمة في الخلفية بحيث يمكن تشغيل برامج متعددة في نفس الوقت ، والذي يُعرف باسم "تعدد المهام". يمنح نظام التشغيل كل برنامج مساحة خاصة به من الذاكرة ، بحيث يصل كل برنامج إلى موارده الخاصة فقط .. في محاولة للحد من ما يمكن أن يفعله برنامج خاطئ أو ضار. يُعرف الاحتفاظ بالبرامج منفصلة في بعض الأحيان باسم "الصندوق الرمل" .. يتوسط الوصول إلى كل برنامج بحيث يعمل بشكل مستقل ، دون التدخل في البرامج الأخرى أو النظام ككل. وبالمثل ، يتمتع كل برنامج ببعض الوصول إلى الشاشة من خلال نافذة ، ولكن يتم فصل منطقة الإخراج هذه عن ناتج البرامج الأخرى.
تذكر أن ملف exe أو أيًا كان ملفًا لتعليمات رمز الجهاز. عندما تنقر نقرًا مزدوجًا فوق البرنامج ، فإن نظام التشغيل هو الذي "يُطلق" البرنامج ، ويقوم بخطوات التدبير المنزلي لتخصيص مساحة ذاكرة داخل ذاكرة الوصول العشوائي للبرنامج ، وتحميل القسم الأول من رمز الجهاز الخاص بالبرنامج في تلك الذاكرة ، و أخيرا توجيه وحدة المعالجة المركزية لبدء تشغيل هذا الرمز.
الكاميرا الرقمية هي أيضًا كمبيوتر صغير. عند بدء التشغيل ، لا يتم تشغيل برنامج إدارة الملفات. بدلاً من ذلك ، بعد إعداد التدبير المنزلي الأساسي ، قد تقوم الكاميرا فقط بتشغيل برنامج واحد يرسم القوائم وما إلى ذلك على شاشة الكاميرا ويستجيب للنقرات على أزرار الكاميرا وما إلى ذلك.
التمهيد / إعادة التشغيل
مشكلة الدجاج والبيض .. من يدير نظام التشغيل؟
عند التشغيل لأول مرة ، يعمل الكمبيوتر على تشغيل برنامج "صغير"
يبحث هذا البرنامج عادةً عن قرص يحتوي على نظام تشغيل لتشغيله
أصل الكلمة: "ارفع نفسك من السياج عن طريق سحب حذائك"
الحذاء - بدء
إعادة تشغيل - إيقاف / بدء دورة جديدة
Operating System
Who starts Firefox?
Operating System
Set of supervisory programs, run when computer first starts
Administration behind the scenes
Starting/managing/ending other programs
--Modern computers can run multiple programs at the same time
--Operating system keeps each program run isolated
--Program has its own RAM, its own windows on screen
--vs. accidental or malicious action between programs
e.g. Laptop
e.g. Digital camera
The "operating system" of a computer is like a first, supervisory program that begins running when the computer first starts up ("boots up"). The operating system plays an invisible administrative and bookkeeping role behind the scenes. When a desktop or laptop starts up, the operating system typically gets things organized and then launches a "file explorer" program which displays windows and menus etc. that show the user what file systems are available, allowing the user to navigate and operate on the files.
The operating system keeps things organized in the background so that multiple programs can run at the same time, which is known as "multitasking". The operating system gives each program its own area of memory, so each program only accesses its own resources .. attempting to limit what an erroneous or malicious program can do. Keeping the programs separate is sometimes known as "sandboxing" .. mediating the access of each program so it operates independently, without interfering with other programs or the system as a whole. Similarly, each program has some access to the screen through a window, but this output area is separated from the output of other programs.
Recall that a .exe file or whatever is essentially just a file of machine code instructions. When you double-click the program, it is the operating system that "launches" the program, doing the housekeeping steps of allocating an area of memory within RAM for the program, loading the first section of the program's machine code into that memory, and finally directing the CPU to start running that code.
A digital camera is also a little computer. When it starts up, it does not run a file manager program. Instead, after the basic housekeeping is set up, the camera may just run a single program that draws the menus etc. on the camera's screen and responds to clicks on the camera's buttons and so on.
Boot / Reboot
Chicken and egg problem.. who runs the operating system?
When first powered on, computer runs a tiny "powered on" program
That program typically looks for a disk containing an operating system to run
Etymology: "lift self over a fence by pulling on your bootstraps"
Boot up -- start
Reboot -- shutdown/start-fresh cycle