DEV Community

Discussion on: Daily Challenge #46 - ???

Collapse
 
serbuvlad profile image
Șerbu Vlad Gabriel

x86_64 assembly (System V ABI, GNU assembler), as usual:

bsure.S:

    .global bsure

    .text
bsure:
    xor %eax, %eax
loop:
    mov (%rsi), %cl

    cmp $63, %cl # '?'
    je skip

    mov %cl, (%rdi)
    inc %rdi
    inc %rax
skip:
    inc %rsi

    cmp $0, %cl
    jne loop

    ret

bsure.h:

/* 
 * bsure - remove question marks from a string
 * if dst and src overlap (or match), that's fine
 * returns the number of bytes copied (including the null byte).
 */
size_t bsure(char *dst, char *src);