?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. /*-------------------------------------------------------------------------
  2.    _strlen.c - part of string library functions
  3.  
  4.    Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
  5.    mcs51 assembler by Frieder Ferlemann (2007)
  6.  
  7.    This library is free software; you can redistribute it and/or modify it
  8.    under the terms of the GNU General Public License as published by the
  9.    Free Software Foundation; either version 2, or (at your option) any
  10.    later version.
  11.  
  12.    This library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this library; see the file COPYING. If not, write to the
  19.    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  20.    MA 02110-1301, USA.
  21.  
  22.    As a special exception, if you link this library with other files,
  23.    some of which are compiled with SDCC, to produce an executable,
  24.    this library does not by itself cause the resulting executable to
  25.    be covered by the GNU General Public License. This exception does
  26.    not however invalidate any other reasons why the executable file
  27.    might be covered by the GNU General Public License.
  28. -------------------------------------------------------------------------*/
  29.  
  30. #include <string.h>
  31.  
  32. #if (!defined (__SDCC_mcs51))
  33.  
  34.   /* Generic routine first */
  35.   size_t strlen ( const char * str )
  36.   {
  37.     register int i = 0 ;
  38.  
  39.     while (*str++)
  40.       i++ ;
  41.  
  42.     return i;
  43.   }
  44.  
  45. #else
  46.  
  47. #if defined(__SDCC)
  48.  #include <sdcc-lib.h>
  49. #endif
  50.  
  51.   /* Assembler version for mcs51 */
  52.   size_t strlen ( const char * str ) __naked
  53.   {
  54.     str;     /* hush the compiler */
  55.  
  56.     __asm
  57.       ; dptr holds pointer
  58.       ; b holds pointer memspace
  59.       ;
  60.  
  61.       ; char *ptr = str:
  62.       mov     r2,dpl
  63.       mov     r3,dph
  64.       ;
  65.  
  66.       ; while ( *ptr ) ptr++;
  67.     L00101$:
  68.       lcall   __gptrget
  69.       jz      L00102$
  70.       inc     dptr
  71.       sjmp    L00101$
  72.       ;
  73.  
  74.     L00102$:
  75.       ; return ptr - str;
  76.       clr     c
  77.       mov     a,dpl
  78.       subb    a,r2
  79.       mov     dpl,a
  80.       ;
  81.       mov     a,dph
  82.       subb    a,r3
  83.       mov     dph,a
  84.       ;
  85.       _RETURN
  86.     __endasm;
  87.   }
  88.  
  89. #endif
  90.