John Mavrick's Garden

Search IconIcon to open search

Last updated Unknown

Status: Tags: #cards/cmpt295/assembly Links: Coding MOC


x86-64 Assembly

Principles

Data

Data management

Operations

  1. Memory referenence => data transfer instructions
    • Transfer data from memory to register using mov*
      • Load (mem → reg)
      • Store (reg → mem)
      • Move (reg → reg)
  2. Arithmetic and logical => data manipulation instructions
    • Perform calculations
      • ex) Arithmetic, logic, shift
  3. Branch and jump => program control instructions
    • Transfer control
    • Unconditional jumps to/from functions
    • Unconditional/conditional branches

Syntax

1
2
func_name:
# do something

Function calls ;; call and ret

Parameters

!Assembly.png

Operands

Insructions

testq ;; param & param

Operation sizes movb size of data transfer ;; 1 byte

movw size of data transfer ;; 2 bytes

movl size of data transfer ;; 4 bytes

movq size of data transfer ;; 8 bytes

mov src, dest ?

cmov src, dest ?

call

syntax: call func where func → label (memory adress of first instruction of callee - function being called) program counter: generic term that specifies next adress of instruction, denoted as %rip (register instruction pointer)

ret

syntax: ret

Example

Caller vs Callee and

multstore

Applies multiplication then stores value into dest

1
2
3
4
5
void multstore(long x, long y, long *dest) {
	long t = mult2(x, y);
	*dest = t;
	return;
}

multstore in assembly

1
2
3
4
5
6
7
0000000000400540 <multstore>:
400540: push %rbx # Save %rbx
400541: mov %rdx,%rbx # Save dest
400544: callq 400550 <mult2> # mult2(x,y)
400549: mov %rax,(%rbx) # Save at dest
40054c: pop %rbx # Restore %rbx
40054d: retq # Return

Multiplies 2 numbers

1
2
3
4
long mult2(long a, long b) {
	long s = a * b;
	return s;
}

mult2 in assembly

1
2
3
4
0000000000400550 <mult2>:
400550: mov %rdi,%rax # a
400553: imul %rsi,%rax # a * b
400557: retq # Return

Procedures


Backlinks

1
list from x86-64 Assembly AND !outgoing(x86-64 Assembly)

References:

Created:: 2022-01-31 14:47


Interactive Graph