NASM 64位编程中大小端机制相关内存访问问题咨询
x86 Assembly Memory Access & Endianness Questions
Let’s break down both of these x86 assembly scenarios clearly, since they revolve around how memory addressing, operand widths, and little-endianness work in x86 systems.
I. First Code Snippet Analysis
First, let’s recap the code in question:
arr dq 1234567887654321H mov rsi, arr mov rbx, [rsi]
Here’s a step-by-step breakdown of what’s happening:
arr dq 1234567887654321Hdefines an 8-byte (64-bit) quadword. Since x86 uses little-endian byte ordering, the bytes are stored in memory from lowest address to highest as:21H → 43H → 65H → 87H → 78H → 56H → 34H → 12H
The least significant byte21Hsits at the lowest memory address, which is exactly whatrsipoints to aftermov rsi, arr.mov rbx, [rsi]: Sincerbxis a 64-bit register, x86-64 automatically uses a 64-bit memory access here. This means it reads 8 consecutive bytes starting at the address inrsi(not just the single21Hbyte), then reassembles them in little-endian order to form the original 64-bit value.
Conclusion for Scenario I
The full 1234567887654321H value (all 8 bytes of arr) will be loaded into rbx, not just the 21H byte.
II. Second Code Snippet Analysis
Recapping the key code snippets:
tempbuff resb 16 arr resb 1234567887654321H mov rbx, qword[arr] mov rsi, tempbuff mov [rsi], rbx
Let’s focus on the critical memory operations:
mov rbx, qword[arr]: Theqwordspecifier explicitly tells the assembler to perform a 64-bit memory read. Even thougharris defined withresb(reserves uninitialized bytes), this instruction reads 8 consecutive bytes starting atarr’s base address, assembles them in little-endian order, and stores the resulting 64-bit value inrbx.- Side note: Since
arris uninitialized, the value loaded intorbxwill be whatever random data existed in that memory region.
- Side note: Since
mov [rsi], rbx: This writes the 64-bit value fromrbxinto memory starting attempbuff(pointed to byrsi). Little-endian ordering applies here too: the least significant byte ofrbxgets stored at the lowest address oftempbuff, followed by the next byte, and so on up to the most significant byte.
Conclusion for Scenario II
qword[arr]reads 8 bytes fromarr’s start to fillrbx.- The 64-bit value in
rbxis then written as 8 consecutive bytes into the start oftempbuff, following little-endian byte order.
内容的提问来源于stack exchange,提问作者asn
相关产品推荐
相关产品推荐

