|
|
1.1 root 1: .file "strchr.s"
2: # @(#)strchr.s 1.5
3: # 3.0 SID # 1.2
4: # Fast assembler language version of the following C-program
5: # strchr
6: # which represents the `standard' for the C-library.
7:
8: # Return the ptr in sp at which the character c appears;
9: # NULL if not found
10: #
11: # char *
12: # strchr(sp, c)
13: # register char *sp, c;
14: # {
15: # do {
16: # if (*sp == c)
17: # return(sp);
18: # } while (*sp++);
19: # return(0);
20: # }
21: .globl _strchr
22: .text
23: .align 2
24: _strchr:
25: .word 0x0000 # pgm uses regs 0,1,2,3,4
26: movq 4(ap),r2 # s1 in r2; `c' in r3
27: L0:
28: locc $0,$65535,(r2) # search for a terminating null
29: bneq L1 # hop onward if we found one
30: locc r3,$65535,(r2) # else look for `c' in this BLOCK
31: bneq L2 # hop if found (r1 points to it)
32: movl r1,r2 # no luck at all in this BLOCK
33: jmp L0 # go back to try next BLOCK
34: L1:
35: subl3 r2,r1,r4 # length of (this segment of) s1 in r4
36: incl r4 # gotta include terminal null
37: locc r3,r4,(r2) # scan for `c' in this (tail) segment
38: beql L3 # skip if not found! (r0 is already 0)
39: L2:
40: movl r1,r0 # else found one, return pointer to user
41: L3:
42: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.