I'm going to write a program to add 2, and 7 then I'll explain how it works after.
That should be the weirdest thing I've shown you in all of my posts right? Well the eax and ebx are the names of registers which are parts in a computer. And the mov is actually the word move but in computers we spell it m o v so when I say mov eax,2 I'm saying put a 2 in eax. ebx is another register but eax is the main register. Registers aren't big parts in a computer they are inside the C.P.U which is a tiny part of a computer that does all the thinking. There are 32 bits (binary digits) in a register. Now we'll go over the program again and I'll show you line by line what goes on with the registers.
mov eax,2 ; This changes the eax register to a 2
mov ebx,7 ; This changes the ebx register to a 7
add eax,ebx ; This adds eax and ebx which changes eax into a 9
Sometimes the problems are long so you need other registers such as ecx and edx to hold the answers.
Now let's try a more complicated example.
mov eax,1 ;This will change eax into a 1
mov ebx,4 ;This will change ebx into a 4
add eax,ebx ;This will add eax and ebx together which will change eax into a 5
mov ecx,eax ;This will copy eax into ecx
mov eax,5 ;This will change eax into a 5
mov ebx,3 ;This will change ebx into a 3
add eax,ebx ;This will add eax and ebx together which will change eax into an 8
add eax,ecx ;This will add eax and ecx together which will change eax into a 13
mov edx,eax ;This will copy eax into edx
mov eax,4 ;This will change eax into a 4
mov ebx,6 ;This will change ebx into a 6
add eax,ebx ;This will add eax and ebx together which will change eax into a 10
add eax,edx ;This will add eax and ebx together which will change eax into a 23
Wow registers seem really powerful. You have to remember what values are where, that can get confusing!ReplyDelete
So you said that registers are in the CPU...are they universal for all programs? Does every program get a set of unique resisters or are they shared?
When given registers are they 0ed out?
//I hope your father has informed you the importance of these two numbers.
move ebx, 9000;
//End of the Program
add eax,ebx; //What happens? will the result 9042?
I look forward to your answer. Sorry for assigning homework over the weekend.
Your Stalker who is afraid you will take his job when you grow up,