You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

x86-64汇编中movzwl与movslq指令含义及地址计算咨询

Breaking Down Your x86-64 Instruction Sequence, Focusing on movzwl and movslq

First, let's walk through the address calculations from the preceding lea instructions—since those set up the registers used by the two instructions you're curious about:

Step 1: Calculate initial rax value

lea (%rsi,%rsi,4),%rax

LEA (Load Effective Address) doesn't access memory—it just computes an address and stores it in the destination register. The formula here is base + index*scale + displacement, so:
rax = rsi + (rsi * 4) = rsi * 5

Step 2: Update rsi using the new rax

lea (%r9,%rax,2),%rsi

Using the rax from step 1, this computes:
rsi = r9 + (rax * 2) = r9 + (rsi_old * 5 * 2) = r9 + (rsi_old * 10)

Step 3: Calculate a new rax value

lea (%r8,%rdx,4),%rax

Another LEA calculation:
rax = r8 + (rdx * 4)


Now let's dive into the two instructions you're asking about

1. movzwl 0x402ac0(%rax,%rax,1),%eax

Let's break this into two parts: address calculation, then the data transfer logic.

  • Address calculation: The memory address is computed as 0x402ac0 + rax + (rax * 1) = 0x402ac0 + (rax * 2)

  • Instruction meaning: movzwl stands for move zero-extended word to longword. Here's what that does:

    • It reads a 16-bit (word) value from the computed memory address.
    • It zero-extends this value to 32 bits: all the upper 16 bits of the result are set to 0, regardless of the input's bit pattern.
    • The final 32-bit value is stored in %eax (the 32-bit subset of the 64-bit %rax register).

    Example: If the memory at 0x402ac0 + rax*2 holds 0xABCD, %eax will become 0x0000ABCD.

2. movslq 0x402740(,%rsi,4),%rdx

Again, split into address calculation and transfer logic:

  • Address calculation: The memory address here is 0x402740 + 0 + (rsi * 4) = 0x402740 + (rsi * 4) (the empty first field in the parentheses means there's no base register used here).

  • Instruction meaning: movslq stands for move sign-extended longword to quadword. Here's the breakdown:

    • It reads a 32-bit (longword) value from the computed memory address.
    • It sign-extends this value to 64 bits: the upper 32 bits are set to the same value as the highest bit (sign bit) of the input 32-bit number. If the input's sign bit is 1 (negative in two's complement), the upper bits are all 1; if it's 0 (positive), the upper bits are all 0.
    • The final 64-bit value is stored in %rdx (a full 64-bit register).

    Example: If the memory at 0x402740 + rsi*4 holds 0xFFFFFFFF (a 32-bit -1), %rdx will become 0xFFFFFFFFFFFFFFFF (the 64-bit -1). If the input is 0x7FFFFFFF (max 32-bit positive), %rdx becomes 0x000000007FFFFFFF.


内容的提问来源于stack exchange,提问作者kyandy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:17:35