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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// TITLE("strrchr")
//++
//
// Copyright (c) 1994 IBM Corporation
//
// Module Name:
//
// strrchr.s
//
// Routine Description:
//
// This function searches a null-terminated string for the
// last occurence of a character.
//
// Author:
//
// Jeff Simon (jhs) 02-Aug-1994
//
// Environment:
//
// User or Kernel mode.
//
// Revision History:
//
// Includes
#include <kxppc.h>
//
// char * strrchr
// (
// const char * string,
// int ch
// )
//
//
// Arguments:
//
// STR1 (r.3) - A pointer to the first block of memory
//
// CHAR (r.4) - A search character
//
// Return Value:
//
// NULL if character is never found
// ptr to the character in string where last match is found
//
//
LEAF_ENTRY(strrchr)
lbz r5,0(r3) # read 1st char
or r9,r3,r3 # cp char ptr
cmpi 0x6,0x0,r4,0x0 # ch ?= Null
cmp 0x0,0x0,r5,r4 # r5 ?= ch
bc 0xc,0x1a,L..2
addi r3,r0,0 # init to Null
beq L..1A # b if 1st ch matched
L..1: # CASE: ch != Null
cmpi 0x6,0x0,r5,0x0 # end of str ?
bc 0xc,0x1a,Fini # all done
lbzu r5,1(r9) # read nxt char
cmp 0x0,0x0,r4,r5 # r4 ?= r5
bne L..1
L..1A: # CASE: match found
or r3,r9,r9 # Update char ptr
lbzu r5,1(r9) # load next char
cmp 0x0,0x0,r4,r5 # r4 ?= r5
beq L..1A
b L..1
L..2: # CASE: char = Null
bc 0xc,0x2,Fini # ret if null found
lbzu r5,1(r3)
cmpi 0x0,0x0,r5,0x0 # Is r5 ?= Null
b L..2
Fini:
LEAF_EXIT(strrchr)
|