2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

x86-64 mov命令における上位bitの扱い

Posted at

以下のマニュアルの情報を抜粋。
http://www.agner.org/optimize/optimizing_assembly.pdf

1.  mov rax, 1111111111111111H ; rax = 1111111111111111H
2.  mov eax, 22222222H         ; rax = 0000000022222222H
3.  mov  ax, 3333H             ; rax = 0000000022223333H
4.  mov  al, 44H               ; rax = 0000000022223344H

1のmovを実行した後のraxの値は、もちろん「1111111111111111H」。
2のmovを実行するとraxの上位32bitは0で埋められるため、raxの値は「0000000022222222H」
しかし、3、4のmovを実行しても上位bitの値は変更されない。
なので、raxの値は3を実行すると「0000000022223333H」、4を実行すると「rax = 0000000022223344H」。

32bitレジスタへのmov命令で上位32bitに0を埋めるのは、以前のレジスタの値との偽の依存をなくす?ためらしい。一方、8、16bitレジスタへのmov命令で上位bitの値を変更しないのは、16/32bitモードとの下位互換のためらしい。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?