Announce SDCC 4.5.0 RC1.
[sdcc.git] / sdcc / device / lib / ds390 / gptr_cmp.c
blob5453a6ac9443079a4229136340bb88cb07301595
1 /*-------------------------------------------------------------------------
2 ; gptr_cmp.asm - C run-time: compare two generic pointers
4 ; Copyright (C) 2011, Maarten Brock
6 ; This library is free software; you can redistribute it and/or modify it
7 ; under the terms of the GNU General Public License as published by the
8 ; Free Software Foundation; either version 2, or (at your option) any
9 ; later version.
11 ; This library is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this library; see the file COPYING. If not, write to the
18 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 ; MA 02110-1301, USA.
21 ; As a special exception, if you link this library with other files,
22 ; some of which are compiled with SDCC, to produce an executable,
23 ; this library does not by itself cause the resulting executable to
24 ; be covered by the GNU General Public License. This exception does
25 ; not however invalidate any other reasons why the executable file
26 ; might be covered by the GNU General Public License.
27 ;------------------------------------------------------------------------*/
29 #ifdef __SDCC_MODEL_FLAT24
31 static void dummy(void) __naked
33 __asm
34 .area HOME (CODE)
36 ; compares two generic pointers.
37 ; if p1 < p2 return NZ and C
38 ; if p1 == p2 return Z and NC
39 ; if p1 > p2 return NZ and NC
40 ; if both are a NULL pointer (yes, we have several) also return Z and NC
42 ___gptr_cmp::
43 mov a,sp
44 add a,#0xFA
45 mov dpl1,a
46 mov a,esp
47 anl a,#0x03
48 addc a,#0xFF
49 mov dph1,a
50 mov dpx1,#0x40
51 inc dps ;select dptr1
52 movx a,@dptr
53 mov ap,a
54 inc dptr
55 movx a,@dptr
56 orl ap,a
57 inc dptr
58 movx a,@dptr
59 orl a,ap
60 clr c
61 jnz 00001$
62 mov a,dpl
63 orl a,dph
64 orl a,dpx
65 ; if both are NULL, return Z and NC
66 jz 00002$
67 00001$:
68 orl dps,#0x80 ;decrement dptr1
69 inc dptr
70 inc dptr
71 anl dps,#0x7F ;increment dptr1
72 movx a,@dptr
73 subb a,dpl
74 mov ap,a
75 inc dptr
76 movx a,@dptr
77 subb a,dph
78 orl ap,a
79 inc dptr
80 movx a,@dptr
81 subb a,dpx
82 orl ap,a
83 inc dptr
84 movx a,@dptr
85 subb a,b
86 orl a,ap
87 ; p2 < p1, return NZ and C
88 ; p2 = p1, return Z and NC
89 ; p2 > p1, return NZ and NC
90 00002$:
91 dec dps ;select dptr0
92 ret
94 __endasm;
97 #endif