I am learning assembly language in my spare time to become a better developer. I have bought a book from Amazon and it will be delivered soon and I am trying to familiarise myself with the basic concepts before I dig in.
I am confused about which general purpose registers I should use for general purpose tasks. I know the C programming language and I have read about calling conventions for assembly and the Windows API.
However, if you have a very simple task e.g. add two numbers together with no references to C etc, then which registers would you use?
I realise this is a basic question.
Whichever ones you want, really.
In first-generation 8086 processors, some of the general-purpose registers (AX, BX, CX, DX) had semi-special purposes as well. For example, the LOOP opcode assumes that your loop counter is in CX; and the DIV opcode stores the results in AX and DX. And some addressing modes could use BX or SI or DI as an offset, but couldn’t use the other general-purpose registers as offsets.
Over succeeding processor generations, some of those special purposes have faded — for example, I think most opcodes now let you use any register as an offset, not just BX. So for the most part, the general-purpose registers are interchangeable.
If you want to follow historical precedent, (E)AX is the “accumulator”, so it would be the traditional place to store e.g. the running total as you’re summing a series of numbers. So if you’re doing addition, and you’re not sure which register to put the result in, (E)AX would be a good default choice.