Skip to content

Instantly share code, notes, and snippets.

@kragen
Created January 10, 2012 03:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kragen/1586826 to your computer and use it in GitHub Desktop.
Save kragen/1586826 to your computer and use it in GitHub Desktop.
### Basic Sierpinski harmony bytebeat t & t >> 8 in as few bytes as possible:
.globl _start
_start: inc %ebx # output fd 1 in %ebx for write()
inc %edx # byte count of 1 in %edx for write()
loop: inc %eax # increment t each time through the loop
push %eax # save it on the stack
and %ah, %al # compute t & t >> 8, our output sample
push %eax # store it on the stack for write()
lea 3(%ebx), %eax # a three-byte way to set %eax to 4 (__NR_write)
mov %esp, %ecx # pass sample pointer to write() (little-endian!)
int $0x80 # invoke system call
pop %eax # discard sample
pop %eax # restore t into %eax
jmp loop # and repeat
### Kragen Javier Sitaker
@kragen
Copy link
Author

kragen commented Jan 10, 2012

Compile with gcc -nostdlib sierpinski-harmony.s and, sadly, you have a 485-byte executable that strips down to 240 bytes, even though it only contains 18 bytes of executable code. FreeFull tells me fasm generates smaller executables, but the Whirlwind Tutorial tells me an ELF executable can be as small as 45 bytes. I'm pretty sure you could use its techniques to get this into an executable under 64 bytes.

@kragen
Copy link
Author

kragen commented Jan 10, 2012

I guess I should mention that if you run this, don't print the output out on your screen. Redirect it ./a.out > /dev/dsp or pipe it ./a.out | aplay or | padsp.

@kragen
Copy link
Author

kragen commented Jan 10, 2012

FreeFull wrote an MS-DOS version at http://paste2.org/p/1860182. 11 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment