x86-64汇编疑问:rbx为何不影响al?mov寄存器赋值困惑
Let’s walk through your two questions clearly—this is a key concept to nail down when starting out with x86-64 assembly!
1. Why does mov rbx, 0 not leave rbx as 0 in the end?
First off, mov rbx, 0 does set the entire 64-bit rbx register to 0 when it executes. The confusion comes from the instruction that follows it: mov bl, al.
x86-64 registers are structured with overlapping subsets:
rbx= full 64-bit registerebx= lower 32 bits of rbxbx= lower 16 bits of rbxbl= lower 8 bits of rbx (the rightmost 8 bits)bh= upper 8 bits of bx (bits 8-15 of rbx)
When you execute mov bl, al, you’re only writing to the lowest 8 bits of rbx. The rest of the register (bits 8-63) stays exactly as they were set by mov rbx, 0—which is 0. So after these three instructions:
mov al, 50→ al = 50 (0x32 in hex)mov rbx, 0→ rbx = 0x0000000000000000mov bl, al→ bl = 50, so rbx becomes 0x0000000000000032 (which is decimal 50)
That’s why the final value of rbx is 50, not 0—you overwrote the lowest 8 bits after setting the whole register to zero.
2. Why doesn’t modifying rbx affect al?
Simple: al and rbx are part of completely separate register families.
alis the lowest 8 bits of the rax register (one of x86-64’s general-purpose registers)rbxis an entirely independent general-purpose register, with its own set of sub-registers (bl, bx, ebx)
In x86-64 architecture, these registers don’t overlap or share bits. Modifying any part of rbx (bl, bx, ebx, or rbx itself) has no impact on rax or its sub-registers (al, ax, eax). They’re separate storage locations in the CPU, so changes to one don’t bleed into the other.
内容的提问来源于stack exchange,提问作者Sean Brady

