Wednesday, May 15, 2013

Registers

I'm going to write a program to add 2, and 7 then I'll explain how it works after.

mov eax,2
mov ebx,7
add eax,ebx

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.


1+4+5+3+4+6

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

1 comment:

  1. Wow registers seem really powerful. You have to remember what values are where, that can get confusing!

    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?

    Example:

    //I hope your father has informed you the importance of these two numbers.
    move eax,42;
    move ebx, 9000;
    //End of the Program

    //New 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,
    Abdulmajid Alnouri



    ReplyDelete