Data transfer instructions

Data transfer instructions, as the name of the group suggests, are used to transfer data between registers or between registers and memory. Some of them may have an immediate value as their source operand. The following example illustrates their usage.

 push  ebx                 ; save EBX register on stack
mov ax, 0xc001 ; move immediate value to AX register
movzx ebx, ax ; move zero-extended content of AX to EBX
; register
; EBX = 0x0000c001
bswap ebx ; reverse byte order of EBX register
; EBX = 0x01c00000
mov [some_address], ebx ; move content of EBX register to
; memory at 'some_address'
; content of 'some_address' =
; 0x01c00000
; The above two lines of code could have
; been replaced with:
; movbe [some_address], ebx
pop ebx ; restore EBX register from stack

Let's take a closer look at the instructions used with the example:

  • PUSH: This instructs the processor to store the value of the operand onto a stack and decrements stack pointer (ESP register on 32-bit systems and RSP register on 64-bit ones).
  • MOV: This is the most commonly used instruction for transferring data:
    • It moves data between registers of the same size
    • It loads a register with either an immediate value or a value read from memory
    • It stores the content of a register to memory
    • It stores the immediate value to memory
  • MOVZX: This is less powerful than MOV by means of addressing modes, as it may only transfer data from register to register or from memory to register, but it has its special feature--the value being transferred is converted to a wider (one that uses more bits) one and is zero extended. As to the addressing modes supported by this instruction, it may only do the following:
    • It moves the byte value from register or memory to a word-sized register and extends the resulting value with zeroes (one byte would be added)
    • It moves byte value from register or memory to a double word-sized register, in which case three bytes would be added to the original value and the value itself would be extended with zeroes
    • It moves word-sized value from register or memory to a double word-sized register, adding two bytes and filling them with the extension value of 0
  • MOVSX is similar to MOVZX; however, the extended bits are filled with the sign bit of the source operand.
  • BSWAP/MOVBE The BSWAP instruction is the easiest way to switch the endianness of a value; however, it is not really a transfer instruction as it only rearranges data within a register. The BSWAP instruction only works on 32/64-bit operands. MOVBE is a more convenient instruction for swapping byte order as it also moves data between the operands. This instruction works on 16, 32, and 64-bit operands. It cannot move data from register to register.
  • POP: This retrieves values previously stored on stack. The only operand of this instruction is the destination where the value should be stored, and it may be a register or a location in memory. This instruction increments the stack pointer register as well.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset