# # Code to detect an easter-egg with AMD64 processors # # assemble/link with "as -o hammer.o hammer.s ; ld -o hammer hammer.o" # # by Vince Weaver # Easter egg pointed out by Adam Sulmicki # # Writing 64-bit assembly is amazingly easy [as in similar to x86] # for the amd64, which is comforting and also somehow perversely # evil at the same time. # # Sycscalls .equ SYSCALL_EXIT, 1 .equ SYSCALL_WRITE, 4 .equ STDOUT,1 .globl _start _start: mov $0x8fffffff,%eax # Load magic value into ax cpuid # call cpuid push %edx # store the result push %ecx # to memory push %ebx push %eax mov $string, %rbx # point to a string push $4 # cycle 4 times writing to string pop %rcx move_to_mem: pop %eax mov %eax,(%rbx) add $4,%ebx loop move_to_mem movb $'\n',(%rbx) # Tack a linefeed onto the end mov $string, %rcx call write_stdout #================================ # Exit #================================ exit: xor %ebx,%ebx xor %eax,%eax inc %eax # put exit syscall number (1) in eax int $0x80 # and exit #================================ # WRITE_STDOUT #================================ # ecx has string # eax,ebx,ecx,edx trashed write_stdout: push %rdx push $SYSCALL_WRITE # put 4 in eax (write syscall) pop %rax # in 3 bytes of code cdq # clear edx xor %ebx,%ebx # put 1 in ebx (stdout) inc %ebx # in 3 bytes of code # another way of doing this: lea 1(%edx), %ebx str_loop1: inc %edx cmpb $0,(%rcx,%rdx) # repeat till zero jne str_loop1 int $0x80 # run the syscall pop %edx ret #============================================================================ # section .bss #============================================================================ .bss .lcomm string, 18