Results 1 to 10 of 10

Thread: [RESOLVED] ax, bx, cx, and dx registers.

  1. #1

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Resolved [RESOLVED] ax, bx, cx, and dx registers.

    I know that these 16 bit registers are these:

    ax - accumulator register
    bx - base address register
    cx - counter register
    dx - data register

    The thing that is boggling my mind is what are the differences between them and how are they properly used? An example would be nice as well.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: ax, bx, cx, and dx registers.

    All are pretty much the same, with just a few differences:
    1) Older CPUs favour ax for arithmetic (it's faster there).
    2) Some instructions ONLY work on some registers. For example, the LOOP and REP instructions always use cx, and the IDIV instruction always operates on ax and dx.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: ax, bx, cx, and dx registers.

    And the newer ones favor eax, right?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: ax, bx, cx, and dx registers.

    eax is 32-bit. ax is simply a part of eax in anything since 386, so newer is relative. (I believe the difference between the registers stopped around the Pentium or Pentium II.)
    The decision between eax and ax is not so much one of speed (although 32-bit CPUs are faster with their native numbers) as one of data size.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: ax, bx, cx, and dx registers.

    Another register specific is ecx which is decremented by the loop instruction.

    e.g.
    Code:
    mov ecx, 4
    someloop:
        imul eax, ecx
        loop someloop
    ecx is decreased by one every iteration.

    But, really, any difference between registers is outdated. You can use them for anything you want as long as you bear in mind any registers that are modified by particular instructions.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: ax, bx, cx, and dx registers.

    I already mentioned LOOP.

    stosd and lodd (or something like that) are register-specific, too.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: ax, bx, cx, and dx registers.

    Other than the fact that I can use eax for arithmetic for speed, or specific registers for things such as LOOP, I can pretty much use whatever register I want, and it wouldn't make much of a difference?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: ax, bx, cx, and dx registers.

    Exactly. Except this: esp, ebp, esi and edi are preserved across function calls in the default convention, meaning that
    1) when you call a library function, you can rely on them being the same afterwards as before and
    2) when you write a function that can be externally called, it is your responsibility to save their values. (A C/C++ compiler with inline assembly will do that for you.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: ax, bx, cx, and dx registers.

    Quote Originally Posted by Jacob Roman
    Other than the fact that I can use eax for arithmetic for speed, or specific registers for things such as LOOP, I can pretty much use whatever register I want, and it wouldn't make much of a difference?
    There is 8 general data regsiters on a 32 bit x86 computer.

    eax, ebx, ecx, edx, esi, edi, ebp, esp

    That last one ESP (Stack Pointer) is one that you can only use freely if you have MMX enabled. Other wise you cannot backup the stack pointer and you're program would crash.

    The last thing that is important to know is on a windows system only EAX, ECX, and EDX are useable without being saved first. That means as far as windows is concerned, when it calls you're function it expects that the values it had in ebx, esi, edi, ebp, and esi will remain there. So push them first and pop them when you're finished (with the exception of esp, use mmx to save and restore it).
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  10. #10

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: ax, bx, cx, and dx registers.

    Ok thanks guys. Problem is Resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width