Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对于data段的描述存在疑惑 #14

Open
r3turn00 opened this issue Aug 2, 2019 · 1 comment
Open

对于data段的描述存在疑惑 #14

r3turn00 opened this issue Aug 2, 2019 · 1 comment

Comments

@r3turn00
Copy link

r3turn00 commented Aug 2, 2019

书中第181页,举例说“i32.const 16 指出该内存段需要填充的数据偏移量为16个32位整数的长度,即64字节。“

想请问一下,这里是指偏移为64个字节,还是初始化的数据占64个字节,也就是offset和length的区别。

个人觉得对于data段讲得不是很清楚,从data段的功能而言——初始化内存,是既需要offset也需要length的,并且数据的存储是否遵循小端序等等也没有提及,希望作者能给一个例子,描述得更清楚一些~

非常感谢!

@Becavalier
Copy link
Owner

Hi, sorry for the delay. For example the following instructions stores an i32 “123” at byte range [4..7]:

i32.const 4    // byte-sized address
i32.const 123  // value to store
i32.store 2 0  // 2 = 32-bit/4-byte alignment, 0 = offset

The first immediate of the instruction "i32.store" is the alignment hint and the second immediate indicates the offset based on the base address you provide by operands (i32.const 4). So, the final address should be the base_addr + offset_addr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants