Skip to content

Accessing information

Operand forms

Operand Forms .

Immediate: constant values.

  • Example: $0x1F

Register: denotes the contents of a register

  • use ra to denote an arbitrary register a and indicate its value with the reference R[ra]

Memory reference:

  • Access some memory location according to a computed address (effective address)

  • Mb[Addr] - a reference to the b-byte value stored in the memory starting at address Addr.

  • Imm(rb,ri,s) => Effective Address = Imm + R[rb] + R[ri]*s

    • Immediate offset Imm
    • A base register rb (must be 64-bit registers)
    • An index register ri (must be 64-bit registers)
    • A scale factor s (must be 1,2,4 or 8),

Example

  • Registers contains these addresses:
RegisterValue
%rax0x100
%rcx0x1
%rdx0x3
  • These address contains these hex value:
AddressValue
0x1000xFF
0x1040xAB
0x1080x13
0x10C0x11
  • Then we have:
OperandValueComment
%rax0x100Register
0x1040xABAbsolute Address
$0x1080x108Immediate
(%rax)0xFFAddress 0x100
4(%rax)0xABAddress 0x104
9(%rax,%rdx)0x11Address 0x10C
260(%rcx, %rdx)0x13Address 0x108
0xFC(,%rcx,4)0xFFAddress 0x100
(%rax,%rdx,4)0x11Address 0x10C

Data movement instructions

Note:

  • All move instruction cannot have both operands refer to memory locations
  • (‘b’,‘w’,‘l’,‘q’) must match the size of the register

Move

InstructionEffectDescription
movb S, DD <- SMove byte
movw S, DD <- SMove word
movl S, DD <- SMove double word
movq S, DD <- SMove quad word
movabsq I, RR <- IMove absolute squad word
  • Source can be: immediate, stored in a register, or stored in memory.
  • Destination can be: register or memory address
  • Example:
movl $0x4050,%eax Immediate--Register, 4 bytes
movw %bp,%sp Register--Register, 2 bytes
movb (%rdi,%rcx),%al Memory--Register, 1 byte
movb $-17,(%esp) Immediate--Memory, 1 byte
movq %rax,-12(%rbp) Register--Memory, 8 bytes

Move with zero-extending

  • Copy from a source (immediate, register or memory address) to a register destination, fill out the remaining bytes of the destination with zeros
InstructionEffectDescription
movzbw S, RR <- SMove zero-extended byte to word
movzbl S, RR <- SMove zero-extended byte to double word (long)
movzbq S, RR <- SMove zero-extended byte to quad word
movzwl S, RR <- SMove zero-extended word to double word
movzwq S, RR <- IMove zero-extended word to quad word

Move with sign-extending

  • Copy from a source (immediate, register or memory address) to a register destination, fill out the remaining bytes of the destination with sign extension.
InstructionEffectDescription
movsbw S, RR <- SignExtend(S)Move sign-extended byte to word
movsbl S, RR <- SignExtend(S)Move sign-extended byte to double word (long)
movsbq S, RR <- SignExtend(S)Move sign-extended byte to quad word
movswl S, RR <- SignExtend(S)Move sign-extended word to double word
movswq S, RR <- SignExtend(S)Move sign-extended word to quad word
movslq S,RR <- SignExtend(S)Move sign-extended double word to quad word

Pushing and Popping Stack Data

Stack Operations