简体   繁体   中英

what are the purpose of different types of assembly registers?

Assume this is in AT&T syntax.

When there is a question such as:

movl (%rdi), %ecx

What is the purpose of %rdi or %ecx ?

I understand the concept of mov(q,l,w,b) or add(q,l,w,b) and so on.

Can we write %rdx instead of %rdi ? If so, what would that change? Why does %rdi exist?

x86_64 has 16 general-purpose registers. 8 are carried over from x86 (eax, ebx, ecx, edx, esi, edi, ebp, esp), and 8 are brand new (r8 through r15).

In past days, registers had very specific functions.

  • eax was the accumulator register on which you principally did arithmetic
  • ebx was the base register from which you did memory address calculations
  • ecx was the count register which held a loop counter
  • edx was the data register which you could use for I/O port access
  • edi was the destination index register which pointed to the "destination" of a string operation
  • esi was the source index register which pointed to the "source" of a string operation
  • ebp was the base pointer which pointed to the base of the current stack frame.
  • esp was the stack pointer.

Initially, when the instruction set was tiny, certain instructions would only operate with certain registers. For example, rep stos instructions use ECX as a counter and stored data into the memory pointed to by EDI .

Nowadays, specialized instructions like that are not as commonly seen, and the instructions which are used nowadays by compilers generally accept any of the general purpose registers. So, these days, you can basically treat the CPU as having 14 registers which are almost fully interchangeable (note that ebp and esp are still used as the base pointer and stack pointer, and are often not usable for other purposes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM