Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active August 14, 2017 20:45
Show Gist options
  • Save cedriczirtacic/cd83c65ba533cd6a0c55041fa3198953 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/cd83c65ba533cd6a0c55041fa3198953 to your computer and use it in GitHub Desktop.
check if 64 or 32 bits using CS segment (64=33, 32=23)
// To try it in i386:
// as --32 -o cs.o cs.S && ld -melf_i386 -o cs cs.o
.section .text
.global _start
_start:
movw %cs, %cx
shr $4, %cx
cmpb $3, %cl
je x86_64
jmp i386
x86_64:
movb $60, %al
movw $64, %di
syscall
i386:
movb $1, %al
movw $32, %bx
int $0x80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment