Why would one use “movl $1,

后端 未结 6 1460
旧时难觅i
旧时难觅i 2021-01-31 10:30

As the title states, why would one use \"movl $1, %eax\" as opposed to, say, \"movb $1, %eax\", I was told that movl would zero out the high order bits of %eax, but isn\'t %eax

6条回答
  •  鱼传尺愫
    2021-01-31 10:39

    %eax is a 32-bit register. To use a smaller width, you need %ax for 16-bits. %ax can be further divided into %ah for the high byte of %ax, and %al for the lower byte. The same goes for the other x86 GPRs.

    Looking at the Intel instruction set reference for the mov instruction, I don't see a variant that can move a single byte into a 32-bit register -- it's probably interpreted as a move into %al.

    Since movl is a 32-bit instruction, the values for the upper bytes will correspond to zeros in the case of an immediate value. If you were moving from memory you would be moving an entire 32-bit word.

    %eax is not zeroed out unless you either movl $0, %eax, or if you xorl %eax, %eax. Otherwise it holds whatever value was previously in there. When you movl $1, %eax, you will end up with 0x00000001 in the register because the 32-bit instruction moves a 32-bit immediate value into the register.

提交回复
热议问题