Placeholder Image

字幕列表 影片播放

  • So without pointers

  • we would find it really difficult to build a general purpose CPU

  • that can do anything

  • rather me drawing it

  • let me get out my book of the original IBM PC's 8088

  • and effectively when the mac boot up

  • when the pc boot up

  • they boot up like this

  • now what we have inside the CPU

  • well is a bit of it witch will do the arithmetic, do the logic, add numbers together

  • do various Boolean algebra, will forget about them for now

  • will talk about them some other time probably already talk about them

  • the other thing you got are registers, so registers are literally

  • a small where you can store a bit of information

  • well some of them do store a bit but actually store few more bits

  • and then you will get a Byte or maybe two Bytes worth

  • so let's go in what the 8088 had

  • and it can store generally in the register eater a Byte or two Bytes

  • if you have a look on this book "THE 8088 Project Book"

  • It's got a list in here of the various bits inside it

  • so we have got the arithmetic logic unit

  • some registers here, some more temporary registers

  • and then these general one's here

  • and a few more that we have got around

  • so we have got some 8 bit and 16 bit ? combined

  • to use eater way and then we have got the 16 bit

  • pointers will come back to that

  • so what all these registers do is allowing to store a 16 bit value

  • or an 8 bit value

  • so they are built into the cpu and the instruction in the cpu

  • will let you set a value in them

  • add a value to what is inside or read a value from one of them

  • that's fine

  • you have got one,two,three,four

  • 16 bit or 8

  • 8 bit values

  • that is not much data

  • and you have got the problem

  • where do you get the program from

  • how to you get more data out of your memory

  • to a? it, well the way you do that

  • is if you look you have other registers

  • witch are called pointer and index registers

  • and this why you need pointers or you cant build a computer

  • because what these are used for

  • is these say, well ok I dont have this value here but I am gonna store here where it is in memory

  • so I am gonna store for example

  • a stack pointer, not the stack but I am gonna store a value that points where the stack is in memory

  • now , really easy way to understand how pointers work

  • think it like the index of the book

  • so if I want to know about stack pointer

  • I will go to the index, if I can find the index

  • and somewhere it says stack pointer

  • here we are, stack pointer, see page 9-10

  • So if i want to find out something I do not go to page 9-10 where it is

  • I go to the index and it tell's me

  • where it is and then go page 9-10

  • pointers work exactly like that

  • they tell you where to find the information

  • just like and index in a book, simple

  • Right, now why do we need them to make the computer work

  • there is two reasons why

  • firstly how do we execute code

  • the code, the program, the instruction that it is going to execute

  • stored in memory and you need to know where that is

  • how the CPU does that

  • go back to are thing

  • and if we look carefully, we find among these registers we talked about

  • 16 bit points to registers

  • look over here "16 bit segment registers and the instruction pointer"

  • an other pointer, a special register

  • and all this is doing is storing the value of where in memory to find the instruction you can execute

  • so when the CPU wants to execute an instruction

  • witch is what it does all the time

  • it goes to the instruction pointer

  • and it has got the address of where that instruction is

  • so it will look in the instruction pointer

  • and it will contain say : FFF ,0 in HEX

  • That is the initial point where a PC will start executing code when you witch it on

  • So it goes to that address

  • looks it up in memory

  • and get the value that is in memory and reads it into

  • the CPU where is can start processing it

  • and it will get that instruction, execute it whatever it is

  • and then it will increment the instruction pointer by how over big that instruction was

  • 8088 instruction get very in size every one bye, two bytes

  • these days it can go up to 16 bytes on x86 chip

  • it will increase the instruction pointer to point to the next instruction and does the same things

  • it looks up where the instruction is in memory, fetch is it, and so one, and so one

  • so if we do not have pointers

  • we can't even execute code

  • we need that instruction pointer or what it is called on other processors program counter, same thing

  • just clear where on the x86

  • this instruction pointer we need that to know where to go to get the instruction

  • so without pointers you can't make a CPU work

  • or get values from memory at least

  • that is fine for executing code

  • but this thing is execute on data

  • how do we get the data in, the same thing

  • we have pointers that contains the address or registers that contain the address of where data is in memory

  • So every time you access a variable in C

  • the assembly that is generated is almost certainly getting to re getting

  • that ? from memory putting it into a register in the CPU

  • and that will be done with having a pointer value where this is in memory

  • going and fetching it and then using that

  • in the instruction that is being executed where ever that might be

  • to add say : on to an other register or where the CPU needs doing

  • so, again without pointers you can not get data from memory you can not store data back into memory

  • so you can not build a computer !

  • without computers you can forget your

  • functional program you can forget your hash tables

  • your link list anything, you cannot build a computer without pointers

So without pointers

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

Essentials:隱藏的指針 - Computerphile (Essentials: Hidden Pointers - Computerphile)

  • 5 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字