Skip to content

Instantly share code, notes, and snippets.

@revmischa
Created November 3, 2013 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revmischa/7285088 to your computer and use it in GitHub Desktop.
Save revmischa/7285088 to your computer and use it in GitHub Desktop.
0000000100000f2e subq $8, %rsp
0000000100000f32 xorl %r12d, %r12d
0000000100000f35 leaq 68(%rip), %r14
0000000100000f3c movl $42, %r15d
new_line:
0000000100000f42 movswl (%r14,%r12,2), %r13d
0000000100000f47 xorl %ebx, %ebx
new_col:
0000000100000f49 btl %ebx, %r13d
0000000100000f4d movl $95, %edi
0000000100000f52 cmovbl %r15d, %edi
0000000100000f56 callq 0x100000f96
0000000100000f5b incl %ebx
0000000100000f5d cmpl $11, %ebx
0000000100000f60 jl 0x100000f49
0000000100000f62 movl $10, %edi
0000000100000f67 callq 0x100000f96
0000000100000f6c incq %r12
0000000100000f6f cmpl $11, %r12d
0000000100000f73 jne 0x100000f42
0000000100000f79 addq $8, %rsp
0000000100000f7d ret
= 80 bytes of code + 22 bytes of 16-bit packed line bitmaps = 102 bytes total __TEXT segment
~~~~~ OSX x86-64 source:
.section __TEXT,__text,regular
.extern _putchar
.globl _main
_main: ## @main
subq $8, %rsp # align stack
xorl %r12d, %r12d # cur line
leaq _bitmap(%rip), %r14 # pointer to bitmap base
movl $42, %r15d # '*'
new_line:
movswl (%r14,%r12,2), %r13d # pointer to bitmap base + line offset
# print line loop
xorl %ebx, %ebx # loop counter = 0
new_col:
# bit test for current char
btl %ebx, %r13d # test bit at current loop index r11 in line pointer
movl $95, %edi # '_'
cmovbl %r15d, %edi # move '*' into %edi to print if bit test succeeds
callq _putchar
incl %ebx # inc cur col
cmpl $11, %ebx # compare to cur col
jl new_col
# end printing line
# print "\n"
movl $10, %edi
callq _putchar
# fetch next line
incq %r12 # inc cur line
cmpl $11, %r12d # compare to cur line
jne new_line
addq $8, %rsp # unalign stack
ret
.globl _bitmap ## @bitmap = 22 bytes
_bitmap:
.short 32 ## 0x20
.short 32 ## 0x20
.short 80 ## 0x50
.short 136 ## 0x88
.short 260 ## 0x104
.short 1539 ## 0x603
.short 260 ## 0x104
.short 136 ## 0x88
.short 80 ## 0x50
.short 32 ## 0x20
.short 32 ## 0x20
~~~~ C source:
#include <stdio.h>
typedef short line;
line bitmap[] = { 32,32,80,136,260,1539,260,136,80,32,32 };
void main() {
int i, j, c;
line l;
for (i = 0; i < 11; i++) {
line l = bitmap[i];
for (j = 0; j < 11; j++) {
c = l & (1 << j);
putchar(c ? '*' : '_');
}
putchar(0x0A);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment