dhilst

gas copy string n ;-)

#
# void
# mycpynstr (char *dst, char *src, int n)
# {
# while (n--)
# *dst++ = *src++;
# }
#
.file "cpystr.c"
.text
.globl mycpynstr
.type cpynstr, @function
mycpynstr:
pushl %ebp
movl %esp, %ebp
jmp .L2 # goto (.L2)

# *dst++ = *src++ at line 6
.L3:
movl 12(%ebp), %eax # move src to %eax
movzbl (%eax), %edx # %dl = (char *) %eax # (src)
movl 8(%ebp), %eax # move dst to %eax
movb %dl, (%eax) # *dst = *src
addl $1, 8(%ebp) # src++
addl $1, 12(%ebp) # dst++

# while (n--) at line 5
.L2:
cmpl $0, 16(%ebp) # if (n != 0)
setne %al # %al = 1
subl $1, 16(%ebp) # n--
testb %al, %al # if (%al)
jne .L3 # goto (.L3)
popl %ebp # else
ret # return

.size mycpynstr, .-mycpynstr
.ident "GCC: (GNU) 4.5.1"
.section .note.GNU-stack,"",@progbits
I made this with `gcc -S cpystr.c' where cpystr.c contains the mycpynfunction
defined as in first eight lines in this file. Then I open the file cpystr.s
created by gcc and add the coments. Nothing more was changed.
The comments tell in C language what is happening. But I not sure if
every comment is exactly right... its just how I understand the code. The
comments start with `#' character and extends to the end of line.
Cheers :-)