Skip to content

Instantly share code, notes, and snippets.

@finkrer
Created December 29, 2020 08:28
Show Gist options
  • Save finkrer/cb0f1c0959d72f40198d29bf6925427a to your computer and use it in GitHub Desktop.
Save finkrer/cb0f1c0959d72f40198d29bf6925427a to your computer and use it in GitHub Desktop.
.globl _start
_start:
# logical operations
mov $0, %rax
mov $1, %rbx
and %rbx, %rax
# rax is now 0
mov $0, %rax
mov $1, %rbx
or %rbx, %rax
# rax is now 1
mov $1, %rax
mov $1, %rbx
xor %rbx, %rax
# rax is now 0
mov $0, %rax
mov $1, %rbx
test %rbx, %rax
# like AND but does not change the result
# flags: SF, ZF, PF
xor %rax, %rax
not %al
# rax is now 255
# shift operations
mov $0xf0, %rax # 1111.0000
shr $3, %al # 0001.1110
shl $4, %al # 1110.0000
mov $0xf0, %rax # 1111.0000
sal $3, %al # 1000.0000
sar $4, %al # 1111.1000
mov $39, %rax # 0010.0111
ror $1, %al # 1001.0011
rol $2, %al # 0100.1110
mov $39, %rax # 0010.0111
rcr $1, %al # 0001.0011, CF=1
rcr $2, %al # 1110.0010, CF=0
# flags: OF
# exit just in case
mov $0x3c, %rax
xor %rdi, %rdi
syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment