Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
[bits 64]
extern rand
extern time
extern srand
extern write
global main
section .text
%define SIZE (31*2048)
main:
; Initialize srand
xor rdi, rdi
call time
mov rdi, rax
call srand
; rbp will always point to the buffer
mov rbp, buf
loop_outer:
; Zero out rbx
xor ebx, ebx
loop_inner:
; Get a random 31-bit number into rax
call rand
; Put the random bits into xmm1 and xmm2
movd xmm1, eax
movd xmm2, eax
; Put the lower 16 bits in xmm1, and the upper 15 in xmm2
pshufb xmm1, [shuffler1]
pshufb xmm2, [shuffler2]
; Zero out xmm0
pxor xmm0, xmm0
; Put a single bit from the random number into each byte of xmm0/xmm1
pand xmm1, [and1]
pand xmm2, [and1]
; Set each byte to 0xff if the bit was 0, otherwise 0
pcmpeqb xmm1, xmm0
pcmpeqb xmm2, xmm0
; Mask out the difference between '/' and '\'
pand xmm1, [and2]
pand xmm2, [and2]
; Add the value for '/', such that each byte is now either '/ or '\'
paddb xmm1, [adder]
paddb xmm2, [adder]
; Save the 31 bytes
movdqu [rbp + rbx], xmm1
movdqu [rbp + rbx + 16], xmm2
add ebx, 31
; Check if done
cmp ebx, SIZE
jne loop_inner
; Print them
mov rdi, 1
mov rsi, rbp
mov rdx, SIZE
call write
; Go again
jmp loop_outer
section .data
align 16
shuffler1: db 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1
shuffler2: db 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3
and1: db 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80
and2: times 16 db 0x2d
adder: times 16 db 0x2f
section .bss
buf: resb SIZE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.