strncpy
Posted Aug 21, 2003 15:08 UTC (Thu) by
paulsheer (guest, #3925)
Parent article:
Kernel release status
on the x86 it is not obvious what he means:
strncpy:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl 16(%ebp), %ecx
movl 8(%ebp), %edx
movl 12(%ebp), %ebx
testl %ecx, %ecx
je .L8
.p2align 4,,7
.L6:
movb (%ebx), %al
movb %al, (%edx)
testb %al, %al
je .L5
incl %ebx
.L5:
incl %edx
decl %ecx
jne .L6
.L8:
popl %ebx
movl 8(%ebp), %eax
popl %ebp
ret
One can see that, in theory, one could do
something like
while (count) {
unsigned char c;
c = *tmp = *src;
c--;
"subc src, -1"
tmp++;
count--;
}
which would work on any architecture.
one of the deficiencies of C (and most (all?)
compiler languages) is that you do not have
direct access to the carry bit.
on the ARM however gcc shines:
strncpy:
cmp r2, #0
mov ip, r0
moveq pc, lr
.L6:
ldrb r3, [r1, #0] @ zero_extendqisi2
cmp r3, #0
addne r1, r1, #1
subs r2, r2, #1
strb r3, [ip], #1
bne .L6
mov pc, lr
-paul
(
Log in to post comments)