如何将值 2^128-1 存储在内存中(16 字节)?

How can I store the value 2^128-1 in memory (16 bytes)?

根据此 link What are the sizes of tword, oword and yword operands? 我们可以使用以下约定存储数字: 16 字节(128 位):oword、DO、RESO、DDQ、RESDQ

我尝试了以下方法:

section .data
   number do 2538

很遗憾出现以下错误returns:

Integer supplied to a DT, DO or DY instruction

我不明白为什么它不起作用

如果你的汇编程序不支持 do 的 128 位整数常量,那么你可以用 dq 将常量分成两个 64 位的一半,例如

section .data
    number do 0x000102030405060708090a0b0c0d0e0f

可以实现为

section .data
    number dq 0x08090a0b0c0d0e0f,0x0001020304050607

除非其他一些代码需要它在内存中,否则动态生成所有 128 位都设置为 1 = 0xFF 的向量会更便宜...重复 = 2^128-1:

pcmpeqw  xmm0, xmm0      ; xmm0 = 0xFF... repeating

;You can store to memory if you want, e.g. to set a bitmap to all-ones.
movups   [rdx], xmm0

另见


对于您在评论中描述的用例,没有理由弄乱 .data.rodata 中的静态数据或 .bss 中的静态存储。只需在堆栈上创建 space 并将指针传递给它。

call_something_by_ref:
    sub      rsp, 24
    pcmpeqw  xmm0, xmm0      ; xmm0 = 0xFF... repeating
    mov      rdi, rsp
    movaps   [rdi], xmm0     ; one byte shorter than  movaps [rsp], xmm0
    lea      rsi, [rdi+8]
    call     some_function
    add      rsp, 24
    ret

请注意,此代码没有大于 8 位的立即数常量(用于数据或地址),并且它只涉及高速缓存中已经很热的内存(堆栈底部)。是的,当 some_function 分别取消引用 RDI 和 RSI 时,存储转发确实可以从宽向量存储到整数加载。