Bryand and O'Hallaron Chapter 3 Section 4.2 Data Movement Data Movement Instructions The various "mov" instructions are two operand instructions with the IA-32 restriction that both operands cannot be in memory. Instruction Effect Description movl S, D D <- S Move double word movw S, D D <- S Move word movb S, D D <- S Move byte movsbl S, D D <- SignExtend(S) Move sign-extended byte movsbl S, D D <- ZeroExtend(S) Move zero-extended byte pushl S R[%esp] <- R[%esp] - 4 Push M[R[%esp]] <- S popl S D <- M[R[%esp]] Push R[%esp] <- R[%esp] + 4 Examples 1 movl $0x4050,%eax #Immediate--Register 2 movl %ebp,%esp #Register--Register 3 movl (%edi,%ecx),%eax #memory--Register 4 movl $17,(%esp) #immediate--Memory 5 movl %eax,-12(%ebp) #Register--Memory Comparing Byte Movement Instructions assume that %dh = 0x8D, %eax = 0x98765432 1 movb %dh,%al # %eax = 0x9876548D 2 movb %dh,%ah # %eax = 0x98768D32 3 movsbl %dh,%eax # %eax = 0xFFFFFF8D 4 movsbl %dh,%eax # %eax = 0x0000008D Push and pop operations push longthing pop longthing ;equivalent code ;equivalent code subl $4,%esp movl (%esp),longthing movl longthing,(%esp) addl $4,%esp address memory (the stack) %esp +-----------------+ 0xbffffffc | |<------ 20(%esp) +-----------------+ 0xbffffff8 | |<------ 16(%esp) +-----------------+ 0xbffffff4 | |<------ 12(%esp) +-----------------+ 0xbffffff0 | third pop |<------ 8(%esp) +-----------------+ 0xbfffffec | second pop |<------ 4(%esp) +-----------------+ +-----------------+ 0xbfffffe8 | first pop |<------ | | %esp +-----------------+ +-----------------+ 0xbfffffe4 | first push |<------ -4(%esp) +-----------------+ 0xbfffffe0 | second push |<------ -8(%esp) +-----------------+ 0xbfffffdc | third push |<------ -12(%esp) +-----------------+ 0xbfffffd8 | |<------ -16(%erg) +-----------------+ 0xbfffffd4 | |<------ -20(%esp) +-----------------+