Accessing information
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:
Register | Value |
---|---|
%rax | 0x100 |
%rcx | 0x1 |
%rdx | 0x3 |
- These address contains these hex value:
Address | Value |
---|---|
0x100 | 0xFF |
0x104 | 0xAB |
0x108 | 0x13 |
0x10C | 0x11 |
- Then we have:
Operand | Value | Comment |
---|---|---|
%rax | 0x100 | Register |
0x104 | 0xAB | Absolute Address |
$0x108 | 0x108 | Immediate |
(%rax) | 0xFF | Address 0x100 |
4(%rax) | 0xAB | Address 0x104 |
9(%rax,%rdx) | 0x11 | Address 0x10C |
260(%rcx, %rdx) | 0x13 | Address 0x108 |
0xFC(,%rcx,4) | 0xFF | Address 0x100 |
(%rax,%rdx,4) | 0x11 | Address 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
Instruction | Effect | Description |
---|---|---|
movb S, D | D <- S | Move byte |
movw S, D | D <- S | Move word |
movl S, D | D <- S | Move double word |
movq S, D | D <- S | Move quad word |
movabsq I, R | R <- I | Move absolute squad word |
- Source can be: immediate, stored in a register, or stored in memory.
- Destination can be: register or memory address
- Example:
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
Instruction | Effect | Description |
---|---|---|
movzbw S, R | R <- S | Move zero-extended byte to word |
movzbl S, R | R <- S | Move zero-extended byte to double word (long) |
movzbq S, R | R <- S | Move zero-extended byte to quad word |
movzwl S, R | R <- S | Move zero-extended word to double word |
movzwq S, R | R <- I | Move 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.
Instruction | Effect | Description |
---|---|---|
movsbw S, R | R <- SignExtend(S) | Move sign-extended byte to word |
movsbl S, R | R <- SignExtend(S) | Move sign-extended byte to double word (long) |
movsbq S, R | R <- SignExtend(S) | Move sign-extended byte to quad word |
movswl S, R | R <- SignExtend(S) | Move sign-extended word to double word |
movswq S, R | R <- SignExtend(S) | Move sign-extended word to quad word |
movslq S,R | R <- SignExtend(S) | Move sign-extended double word to quad word |