Results 1 to 8 of 8
  1. #1
    Lehsyrus's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Jersey
    Posts
    10,893
    Reputation
    1281
    Thanks
    3,130

    Stupid question of the day

    I understand what registers are, however I don't understand what exactly it is that they do. I'm learning assembly for the 80x86 system, and I know that the E before the next two letters stands for "extended" over the standard 16-bit register system, however I do not understand the registers actual functions.

  2. #2
    [implicit]'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    1
    My Mood
    Cynical
    The registers store data in active memory. It's not really important you know how they work. But they are faster (require less clock cycles) to use than accessing data from somewhere in memory (variables).

    They can all be used for basically anything, with the exception of EIP which points to the next instruction. However, some instructions use specific registers so to optimize you want to make sure you use the right register:

    eax - most commonly used for everything. WinAPI functions return with eax, mul, div use eax, etc.
    ebx - general data use (can't think of any specific instructions)
    ecx - counter, loop uses it
    edx - again, general data, but things like mul and div that cannot be only stored in eax will overflow into edx so you can use it as a 64 bit number eax:edx
    esi - string source, used in string operations, points to input string
    edi - string destination, used in string operations, points to outputted string
    esp - stack pointer, points to the top of the stack (access things on the stack)
    ebp - base pointer, points to the base of the stack (useful in procedures to access local variables)

  3. #3
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by [implicit] View Post
    The registers store data in active memory. It's not really important you know how they work. But they are faster (require less clock cycles) to use than accessing data from somewhere in memory (variables).
    Its not faster just because yes.
    Registers are themselves saved on the CPU, not in memory (variables for example). And yes it is important that you know how they work. Jeez, its the point of learning ASM even, in my opinion.

    And of course, it is obviously faster when you are trying to access something inside the cpu. (Way... but way faster, the cpu doesn't need to access RAM (memory..) or the cache.. (w/e)
    Last edited by 'Bruno; 11-12-2012 at 02:43 AM.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  4. #4
    [implicit]'s Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    1
    My Mood
    Cynical
    Quote Originally Posted by 'Bruno View Post


    Its not faster just because yes.
    Registers are themselves saved on the CPU, not in memory (variables for example). And yes it is important that you know how they work. Jeez, its the point of learning ASM even, in my opinion.

    And of course, it is obviously faster when you are trying to access something inside the cpu. (Way... but way faster, the cpu doesn't need to access RAM (memory..) or the cache.. (w/e)
    Unless you're designing processors, it's not really important to learn the physical aspects of how it works. He doesn't need an in-depth explanation of how you have clock cycles and how instructions work; writing efficient asm code just requires you know how to connect the registers to their common instructions and how many clock cycles each one takes. Fetching variables from memory takes more time because their values have to be loaded into the processor for the instruction, but it's irrelevant as long as you understand mov eax,0 takes ?4? clock cycles and 5 bytes vs xor eax,eax which takes ?2? clock cycles and 2 bytes because one loads from memory, the other just uses values already on the processor.

  5. #5
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by [implicit] View Post
    Unless you're designing processors, it's not really important to learn the physical aspects of how it works. He doesn't need an in-depth explanation of how you have clock cycles and how instructions work; writing efficient asm code just requires you know how to connect the registers to their common instructions and how many clock cycles each one takes. Fetching variables from memory takes more time because their values have to be loaded into the processor for the instruction, but it's irrelevant as long as you understand mov eax,0 takes ?4? clock cycles and 5 bytes vs xor eax,eax which takes ?2? clock cycles and 2 bytes because one loads from memory, the other just uses values already on the processor.
    Oh so everyone nowadays want to design cpus?

    ./facepalm
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  6. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    I think the concept was thoroughly explained.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  7. #7
    Lehsyrus's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    Jersey
    Posts
    10,893
    Reputation
    1281
    Thanks
    3,130
    Quote Originally Posted by [implicit] View Post
    The registers store data in active memory. It's not really important you know how they work. But they are faster (require less clock cycles) to use than accessing data from somewhere in memory (variables).

    They can all be used for basically anything, with the exception of EIP which points to the next instruction. However, some instructions use specific registers so to optimize you want to make sure you use the right register:

    eax - most commonly used for everything. WinAPI functions return with eax, mul, div use eax, etc.
    ebx - general data use (can't think of any specific instructions)
    ecx - counter, loop uses it
    edx - again, general data, but things like mul and div that cannot be only stored in eax will overflow into edx so you can use it as a 64 bit number eax:edx
    esi - string source, used in string operations, points to input string
    edi - string destination, used in string operations, points to outputted string
    esp - stack pointer, points to the top of the stack (access things on the stack)
    ebp - base pointer, points to the base of the stack (useful in procedures to access local variables)
    Quote Originally Posted by Bruno;6928822][FONT="Courier New"]

    Its not faster just because yes.
    Registers are themselves saved on the CPU, not in memory (variables for example). And yes it is important that you know how they work. Jeez, its the point of learning ASM even, in my opinion.

    And of course, it is obviously faster when you are trying to access something inside the cpu. (Way... but way faster, the cpu doesn't need to access RAM (memory..) or the cache.. (w/e)[/FONT][/QUOTE]

    [QUOTE='[implicit];6938041
    Unless you're designing processors, it's not really important to learn the physical aspects of how it works. He doesn't need an in-depth explanation of how you have clock cycles and how instructions work; writing efficient asm code just requires you know how to connect the registers to their common instructions and how many clock cycles each one takes. Fetching variables from memory takes more time because their values have to be loaded into the processor for the instruction, but it's irrelevant as long as you understand mov eax,0 takes ?4? clock cycles and 5 bytes vs xor eax,eax which takes ?2? clock cycles and 2 bytes because one loads from memory, the other just uses values already on the processor.
    Quote Originally Posted by 'Bruno View Post


    Oh so everyone nowadays want to design cpus?

    ./facepalm
    Your guys's discussion actually taught me everything I needed to know, thanks!

    Quote Originally Posted by why06 View Post
    I think the concept was thoroughly explained.
    More thoroughly than either of my two textbooks on the subject. I'll definitely be posting here more often, I'm falling in love with ASM, it's so raw I can actually understand it, if that makes sense.

  8. #8
    Fovea's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    325
    Reputation
    101
    Thanks
    411
    My Mood
    Amused
    Efficient code is way more complicated than counting clock cycles... The clock cycle count of an instruction is the least of your worries.
    Last edited by Fovea; 11-15-2012 at 05:22 PM.

  9. The Following User Says Thank You to Fovea For This Useful Post:

    'Bruno (11-16-2012)

Similar Threads

  1. Question of the Day: Favorite Mode/Map
    By Coke in forum CrossFire Discussions
    Replies: 17
    Last Post: 01-01-2011, 11:49 AM
  2. Question of the Day: Annoying Moment.
    By Coke in forum CrossFire Discussions
    Replies: 29
    Last Post: 09-23-2010, 09:47 PM
  3. Question of the Day: Melee Weapons.
    By Coke in forum CrossFire Discussions
    Replies: 19
    Last Post: 09-22-2010, 11:40 PM
  4. Question of the Day: Clans
    By Coke in forum CrossFire Discussions
    Replies: 15
    Last Post: 09-20-2010, 08:11 PM
  5. Interview Question of the Day (IQOD) #1
    By B1ackAnge1 in forum C++/C Programming
    Replies: 26
    Last Post: 09-18-2009, 04:24 PM