使用nasm将数字移入内存

时间:2016-04-22 09:52:44

标签: assembly nasm

我是 public String getDeparture() { return data != null ? data.departure : null; } 编程的新手。我想在变量

中存储整数值
nasm

这会将我的SECTION .bss temp: RESB 8 SECTION .text global _start _start: mov eax,4 mov [temp],eax 值移动到临时位置的开头。但我想把它移到integer。由于整数占用2个字节,我想在开始时但不在2nd location的下一个位置存储4。我怎样才能做到这一点?此外,在检索值时,我将如何从temp+2位置检索,假设我有4个整数,每个占用2个字节。

1 个答案:

答案 0 :(得分:2)

要存储2字节整数,请使用ax寄存器而不是eaxax对应eax的2个最低字节。)

要存储在temp + 2,请存储在temp + 2:)

所以:

mov [temp+2], ax

您可以类似地将值检索到ax寄存器中:

mov ax, [temp+2]

或者您可以将零扩展或符号扩展移动到eax

movzx eax, word [temp+2]
movsx eax, word [temp+2]

(如果值未签名则使用第一个,如果签名则使用第二个。)

相关问题