All pastes #2131061 Raw Edit

Unnamed

public text v1 · immutable
#2131061 ·published 2012-03-22 08:27 UTC
rendered paste body
        .file   "mystrlen.c"
        .text
.globl mystrlen
        .type   mystrlen, @function
mystrlen:
        movq    $0 , %rax       # set return value to 0 
        push    %rbx

mainwhile:  
        movq    (%rdi), %rbx    # read bytes from memory
        movq    $0 , %rcx       # set counter to zero for inner loop    

checkfornulls:
        incq    %rcx            # increment inner counter
        cmp     %bh , 0         # compares value pointed to by first arg to zero 
        je      end             # return if value is zero 

        incq    %rax            # value isn't zero so add 1 to the main counter

        cmp     %rcx, 8         # counter is 8
        jge     endwhile        # so return to outer loop
        rol     %rbx            # rotate current value right
        jmp     checkfornulls   # counter isn't 8 so loop again 
        

endwhile:
        movq    $0 , %rcx       # reset inner counter to zero for reuse
        incq    %rdi            # increment string pointer by 1 
        jmp     mainwhile       # return to beginning of loop
end:
        pop     %rbx
        ret