# strlen # # gcc xstrlen.s -o xstrlen # # $ ./xstrlen foobar # .section .data .equ LINUX_SYSCALL, 0x80 .equ SYS_EXIT, 1 output: .asciz "%d\n" debug: .asciz ":%s:\n" .section .text .globl main main: movl 8(%esp), %eax movl 4(%eax), %eax pushl %eax call strlen addl $4, %esp pushl %eax pushl $output call printf addl $8, %esp movl $0, %ebx movl $SYS_EXIT, %eax int $LINUX_SYSCALL strlen: pushl %ebp movl %esp, %ebp movl $0, %ebx movl 8(%ebp), %eax pushl %eax strlen_loop: movl (%esp), %eax addl %ebx, %eax cmpb $0, (%eax) je strlen_end addl $1, %ebx jmp strlen_loop strlen_end: movl %ebx, %eax movl %ebp, %esp popl %ebp ret