Do we also refer to the registers RAX, RBX etc as R1, R2 and so on?

狂风中的少年 提交于 2019-12-07 10:08:21

问题


I am studying 8086/8080 microprocessors. The registers used in them have names,

  1. RAX
  2. RBX
  3. RCX
  4. RDX

and go on until R8 when the registers are named as R8, R9... to R15. I wanted to know

Do we also refer to the registers RAX, RBX etc as R1, R2 and so on?


回答1:


Standard practice is for the first 8 registers to keep their historical name. This convention is used in the documentation from Intel and AMD and in most assemblers.

The reason for this is that these names are mnemonic for the function of the register. For example rsp sticks out as the stack pointer; r4 not so much. The new registers, by contrast, don't have any particular function.

That being said you can always use macros to define r0-r7 as rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi. For example you can get these definitions in nasm with

%use altreg

Again, this is non-standard and will make the code hard to read, both for you and others.




回答2:


First, 8086/80386/x86-64 and 8080/8085 are completely different architectures. 8080 is an 8-bit CPU and 8086 is a 16-bit one, with the 8085 extends 8080's instruction set and 80386 and x86-64 being the 32 and 64-bit extended ISAs of 8086. Being different architectures, they are not binary compatible. And if you're learning about Rxx then it's the 64-bit x86-64 and not 8086. 8086 is a CPU with the x86-16 instruction set, not architecture although its instruction set might sometimes be called 8086. The architecture name is addressed as x86 in general, or occasionally x86-64

For the question, RBX is not R2. The real encoded order is AX, CX, DX, BX. And registers are often (almost always) counted from zero, so RBX should be R3, and AX, CX, DX would be R0, R1, R2 respectively. In nasm you can also use those numbered registers with %use altreg

5.1 altreg: Alternate Register Names

The altreg standard macro package provides alternate register names. It provides numeric register names for all registers (not just R8–R15), the Intel-defined aliases R8L–R15L for the low bytes of register (as opposed to the NASM/AMD standard names R8B–R15B), and the names R0H–R3H (by analogy with R0L–R3L) for AH, CH, DH, and BH.

https://nasm.us/doc/nasmdoc5.html

FYI, in the intel-8080 registers are encoded like this

000  0    B
001  1    C
010  2    D
011  3    E
100  4    H 
101  5    L
111  7    A

not in alphabetical order either

See Why are first four x86 GPRs named in such unintuitive order?



来源:https://stackoverflow.com/questions/9129933/do-we-also-refer-to-the-registers-rax-rbx-etc-as-r1-r2-and-so-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!