Why would one use “movl $1,

后端 未结 6 1462
旧时难觅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:47

    opposed to, say, "movb $1, %eax"

    This instruction is invalid. You can't use eax with the movb instruction. You would instead use an 8-bit register. For example:

    movb $1, $al

    but isn't %eax a register that's equivalent to the size of the system's wordsize?

    No. EAX will always be a 32-bit value, regardless of the system's register size.

    You are confusing C variable sizes with register sizes. C variable sizes may change depending on your system and compiler.

    Assembly is simpler than C. In GAS assembly, instructions are suffixed with the letters "b", "s", "w", "l", "q" or "t" to determine what size operand is being manipulated.

    * b = byte (8 bit)
    * s = short (16 bit integer) or single (32-bit floating point)
    * w = word (16 bit)
    * l = long (32 bit integer or 64-bit floating point)
    * q = quad (64 bit)
    * t = ten bytes (80-bit floating point)
    

    These sizes are constant. They will never be changed. al is always 8-bits and eax is always 32-bits.

提交回复
热议问题