[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. :)
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.
Re: ax, bx, cx, and dx registers.
And the newer ones favor eax, right?
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.
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.
Re: ax, bx, cx, and dx registers.
I already mentioned LOOP.
stosd and lodd (or something like that) are register-specific, too.
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?
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.)
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).
Re: ax, bx, cx, and dx registers.
Ok thanks guys. Problem is Resolved. :)