Bitwise in Assembly
and, or, xor, shl: arithmetic below arithmetic.
; and, or, xor, and the shifts: arithmetic below arithmetic.
global _start
section .text
_start:
mov rax, 0b1100
mov rbx, 0b1010
mov rcx, rax
and rcx, rbx ; 0b1000 = 8
mov rdx, rax
or rdx, rbx ; 0b1110 = 14
xor rax, rbx ; 0b0110 = 6
shl rax, 2 ; 24
add rax, rcx ; 32
add rax, rdx ; 46
mov rdi, rax
mov rax, 60 ; exit code 46
syscall
How it works
- Binary literals like
0b1100keep the bits visible. andmasks,ormerges,xordifferences.shl rax, 2multiplies by four in one shift.
Keywords and builtins used here
addandglobalmovorraxrbxrcxrdirdxsectionshlsyscallxor
The run, in numbers
- Lines
- 20
- Characters to type
- 416
- Tokens
- 64
- Three-star pace
- 55 tpm
At the three-star pace of 55 tokens a minute, this run takes about 70 seconds.
Step 1 of 4 in Bits & flags, step 15 of 31 in Language basics.