I just want to verify if the CPU itself supports names of "registers". I mean arg0 arg1 arg2... etc is at the end "names". Does the CPU support also names?! I'm not asking about the register itself, I'm asking whether the CPU supports names of the registers which it can manipulate or not?
-
([You will regret asking (at this stage of learning about computers)](https://en.m.wikipedia.org/wiki/Register_renaming).) – greybeard Feb 09 '19 at 14:06
-
what's confusing me that how hardware are dealing with names!! because names is something magically not physical .. – Ryan Feb 09 '19 at 14:58
1 Answers
names is something magically not physical
That's the point. Names are purely for us humans to read. The CPUs absolutely have no notion of names. The only things they deal with are numbers. Characters are numbers, addresses are numbers, instructions are numbers... So are registers which are also just numbers encoded somehow in the instruction itself
Once assembled, there are only numbers in the instruction stream. Even jump labels, functions... don't exist in the executable binary. They're described relatively as "the 14th instruction after this", "the instruction 48 bytes before"... or absolutely as "the function at address 0xFACECAFE". Names, if any, are put in separate sections to describe what an address represents, otherwise no one knows what the variable 0x65DAB3CF or the function at 0xFACECAFE is. Those names are used for debuggers to print the variables for people to read, or for linkers, loaders... to find the correct place to replace the addresses. The CPUs completely ignore them
For example in MIPS $ra is the register number 31, $t9 is 25, $a3 is 7... and those will be encoded as such in the instruction as their binary values. ADD $s2, $t5, $a3 will be encoded as
000000 (R-type instruction opcode) - 01101 ($13/$t5) - 00111 ($7/$a3) - 10010 ($18/$s2) - 00000 (shift amount) - 100000 (32 - ADD function), i.e. 0x01A79020
Likewise in x86 the registers RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, R8-R15 are mapped to 0-15 respectively. xor ecx, esi is encoded as 31 f1 = 00110001 11110001 with the the last 6 bits store the 2 parameters. More complex instructions need more complex rules, for example ADD r9, [rax + 4*r13 + 20] is encoded as 4e 03 4c a8 14
Since CPUs only care about the numbers, it's actually possible to construct an encoding that maps the character strings for register names to the registers themselves. For example r20 would be encoded as 72 32 30 (which are ASCII values of the string "r20") inside the instruction, but why waste so much valuable space in the instruction? A map from r20 to 20 (0x14) is simple and clear enough
See also Are registers real? Do they exist in CPU physically?
- 37,963
- 15
- 156
- 475