Skip to content

Instantly share code, notes, and snippets.

@sunnyone
Created October 31, 2011 18:47
Show Gist options
  • Select an option

  • Save sunnyone/1328429 to your computer and use it in GitHub Desktop.

Select an option

Save sunnyone/1328429 to your computer and use it in GitHub Desktop.
small strlen test assembled
.file "stlen.c"
.section .rodata
.LC0:
.string "Unhappy?: %ld\n"
.text
.globl print_length
.type print_length, @function
print_length:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
pushl %edi
subl $52, %esp
movl 8(%ebp), %eax
movl $-1, -28(%ebp)
movl %eax, %edx
movl $0, %eax
movl -28(%ebp), %ecx
movl %edx, %edi
.cfi_offset 7, -12
repnz scasb
movl %ecx, %eax
notl %eax
subl $1, %eax
movl %eax, -12(%ebp)
movl $.LC0, %eax
movl -12(%ebp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
addl $52, %esp
popl %edi
.cfi_restore 7
popl %ebp
.cfi_def_cfa 4, 4
.cfi_restore 5
ret
.cfi_endproc
.LFE0:
.size print_length, .-print_length
.section .rodata
.align 4
.LC1:
.string "Unhappy, world! Unhappy, world!"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $32, %esp
movl $.LC1, 24(%esp)
movl $100, (%esp)
call malloc
movl %eax, 28(%esp)
movl 24(%esp), %eax
movl %eax, 4(%esp)
movl 28(%esp), %eax
movl %eax, (%esp)
call strcpy
movl 28(%esp), %eax
movl %eax, (%esp)
call print_length
movl $0, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment