File: strrev.S

package info (click to toggle)
avr-libc 20020203-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,448 kB
  • ctags: 6,562
  • sloc: ansic: 7,631; asm: 4,424; sh: 2,703; makefile: 338; pascal: 289
file content (52 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
   strrev.S
   Reverse a string

   Contributors:
     Created by Reiner Patommel

   THIS SOFTWARE IS NOT COPYRIGHTED

   This source code is offered for use in the public domain.  You may
   use, modify or distribute it freely.

   This code is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
   DISCLAIMED.  This includes but is not limited to warranties of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "macros.inc"

#define str_hi r25
#define str_lo r24
#define ltemp  r23
#define rtemp  r22

; char *strrev(char *string)

    .text
    .global _U(strrev)
    .type   _U(strrev), @function

_U(strrev):
    LOAD_X(str_lo, str_hi)	; X is start of string
	LOAD_Z(str_lo, str_hi)	; Z becomes end of string
.strrev_eos:
	LD    __tmp_reg__, Z+
	TST   __tmp_reg__
	BRNE  .strrev_eos
	SBIW  ZL, 2				; now Z points at end of string
.strrev_loop:
	CP    XL, ZL
	CPC   XH, ZH			; if X >= Z we are done
	BRSH  .strrev_done
	LD    ltemp, X          ; get left character
	LD    rtemp, Z			; get right character
	ST    Z, ltemp
	SBIW  ZL, 1
	ST    X+, rtemp			; swap chars
	RJMP  .strrev_loop		; next pair
.strrev_done:
    RET
.strrev_end:
	.size _U(strrev), .strrev_end - _U(strrev)