assembly-related

asm & syscalls

move value into register:

1
mov rax, 60

dereference a pointer:

1
mov rdi, [1337000]

let the asm program executable:

1
2
3
4
.intel_syntax noprefix
.global _start
_start:
<asm_code>

exit():

1
2
3
mov rdi, <exit_code>
mov rax, 60
syscall

write():

1
2
3
4
5
mov rdi, <1_or_2>
mov rsi, <memory_addr>
mov rdx, <bytes>
mov rax, 1
syscall

read():

1
2
3
4
5
mov rdi, 0
mov rsi, <memory_addr>
mov rdx, <bytes>
mov rax, 0
syscall

assemble the program:

1
2
3
gcc -nostdlib hello.S -o hello # assemble the code
objdump -M intel -d hello # read the code
objcopy --dump-section .text=hello_bin_code hello # extracting binary code

arithmetic:

1
2
3
add <reg> <opr> # reg += opr
sub <reg> <opr> # reg -= opr
imul <reg> <opr> # reg *= opr

specially, for division:

1
div <reg> # rax = {rdx, rax} / reg, rdx = remainder

shifting

1
2
shl <reg1> <reg2> # reg1 << reg2
shr <reg1> <reg2> # reg1 >> reg2

and, not, or, xor could be use to process bitwise operations

stack:

1
2
push <reg>
pop <reg>

jump:

1
jmp reg # jump to the addr in the reg

repeat the instruction:

1
2
3
.rept 0x51
nop # repeat nop for 0x51 times
.endr

compare:

1
2
cmp dword ptr [edi] 0x12345678
je label

ja must jump to a label not an address

Licensed under CC BY-NC-SA 4.0
Maybe making a better tomorrow...
Built with Hugo
Theme Stack designed by Jimmy