Assembly language registers
Assembly language programming is actually quite primitive. You'll soon realise that about all the computer's processor can do is interact with data in the computer's memory and with the data in its own internal data stores, which are called registers. Your job as a computer programmer is to write code that tells the CPU what data to move where.
For the time being, we'll just be doing 32 bit coding, so the internal registers in the CPU, for us, will be 32 bits. Each bit is capable of storing a 1 or a 0.
The advantage of registers over computer memory is that they are extremely fast. Time critical programming applications often try to maximize the amount of computation that can be done in the CPU registers, instead of in the computer's memory.
The CPU has four general purpose programming registers, EAX, EBX, ECX and EDX and a number of other specialised registers.
Each of the four general purpose programming registers is 32 bits wide, but we can access the lower 16 bits of EAX (called AX) if we want to. Similarly the lower 16 bits of EBX is called BX, etc. Furthermore, we can access both the upper and lower 8 bits of AX (called AH and AL respectively), too, and similarly for BX, CX and DX. Refer to Diagram 1 below to see how EAX is laid out.
We'll introduce the other specialised CPU registers as we need them. For now the general purpose registers will be sufficient for us to get started with low level programming.
The first thing we will want to learn about programming at the level of the CPU, is how to put data into registers. For this we use the MOV instruction. (This is the first real assembly programming instruction we've met.)
Here is a code fragment which moves the number 47 into the EDX register:
MOV EDX, 47
Or, suppose that we wanted to move the hexadecimal number A4C9 into the 16 bit AX register:
MOV AX, 0A4C9h
(Note the leading zero, and the trailing h, to denote that the number is hexadecimal.)
You might also like
Category Theory and Computer Programming: Tutorial and Workshop, Guildford, U.K., September 16 - 20, 1985. Proceedings (Lecture Notes in Computer Science)