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

AT&T汇编:能否将%edx中"Hello to e"子串转移至%eax及实现方法

Can we move "Hello to e" into %eax?

Short answer: No, you can't fit the entire substring directly into %eax—here's why, plus workable alternatives.

First, a quick clarification: It's a misstatement to say %edx "stores the string" itself. 32-bit registers like %edx only hold 4 bytes of data, and the full string "Hello to everyone" is way longer than that. What you likely mean is %edx holds the memory address of the string, which is also stored at 12(%ebp) (so both point to the same starting location in memory).

Now, onto the main question: The substring "Hello to e" is 10 ASCII characters long (each character takes 1 byte, so 10 bytes total). %eax is a 32-bit register, which can only hold 4 bytes max—even the 64-bit version (%rax) only holds 8 bytes. There's no way to cram 10 bytes into a register that's only designed for 4 or 8. Hardware-wise, it's impossible.

If your goal is to work with this substring (rather than shoving the whole thing into %eax), here are two standard approaches:

1. Store the substring's starting address in %eax

Since "Hello to e" is the first part of the original string, its starting address is the same as the full string's address. You can load this pointer into %eax with a simple move:

# For 32-bit x86:
movl 12(%ebp), %eax
# For x86-64 systems (using 64-bit registers):
movq 12(%rbp), %rax

Now %eax/%rax holds the address of your substring's first character. You can then access individual characters or manipulate the substring using this pointer (e.g., movb (%eax), %cl to grab the first character "H", or addl $9, %eax to jump to the last character "e" of the substring).

2. Load the first few bytes into %eax (if partial data is enough)

If you only need the first 4 characters ("Hell") or 8 characters ("Hello to") of the substring, you can load those directly as a packed value:

# Load first 4 bytes ("Hell") into %eax (32-bit):
movl 12(%ebp), %eax
# Load first 8 bytes ("Hello to") into %rax (x86-64):
movq 12(%rbp), %rax

But remember: this only gives you a chunk of the substring, not the full 10-byte sequence.

To wrap up: Registers have fixed, limited sizes—they can't hold variable-length data like full strings. Using a pointer (storing the substring's address in %eax) is the standard, practical way to handle this in assembly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:35:08