Skip to content

Faster _strlen routine: bonus is that it is fully 32 bit compliant. inputstring A2, output length D0 = 32 bit value #124

@ManuelAndre123

Description

@ManuelAndre123

Adding txt file of routine since Github does not like my formatting??? See below for attachment.

Assuming register A2 as the source register as per string.s, returning length in register D0

Fastest byte string lenght routine using post-increment and initial string address to compute length returned in register D0

_strlen
MOVE.L A2,D0 ;lsave the startaddress of our string into register D0 ;
StringsizeLoop: ; our test .loop label, take notice of the ":" at the end
TST.B (A2)+ ; test character A2 points to + post-increment the address pointer to next character
BNE.S StringsizeLoop ; is character not equal to 0, check next (remember, it is c-style Null terminated)
SUB. L D0,A2 ; we found end of c-style string terminator, so substact the start from the end
MOVE.l A2,D0 ;move the result to data register d0 for returning the value
SUBQ.L #1,d0 ; substract 1 from the result since it points to the C-style Null-terminator!
RTS

_strlen.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions