Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic / libsdcc / _gptrget2.S
1 ; -------------------------------------------------------------------------
2 ;  _gptrget2.S - read two bytes pointed to by a generic pointer
3 ;
4 ;       Written By      Raphael Neider <rneider AT web.de> (2005)
5 ;
6 ;  This library is free software; you can redistribute it and/or
7 ;  modify it under the terms of the GNU Library General Public
8 ;  License as published by the Free Software Foundation; either
9 ;  version 2 of the License, or (at your option) any later version.
10 ;
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 GNU
14 ;  Library General Public License for more details.
15 ;
16 ;  You should have received a copy of the GNU Library General Public
17 ;  License along with this library; if not, write to the 
18 ;  Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
19 ;  Boston, MA  02111-1307  USA.
20 ;
21 ;  In other words, you are welcome to use, share and improve this program.
22 ;  You are forbidden to forbid anyone else to use, share and improve
23 ;  what you give them.   Help stamp out software-hoarding!
24 ;
25 ;  $Id: _gptrget2.S 4148 2006-05-01 20:47:12Z tecodev $
26 ;  ------------------------------------------------------------------------
27
28 ; calling conventions:
29 ;   3 byte generic pointer is passed in via (WREG STK00 STK01).
30 ;   The result is returned in (WREG (STK00 (STK01 (STK02)))).
31 ;
32 ;   unsigned char _gptrget  (void *gptr);
33 ;   unsigned char _gptrget1 (void *gptr);
34 ;   unsigned int  _gptrget2 (void *gptr);
35 ;   void *        _gptrget3 (void *gptr);
36 ;   unsigned long _gptrget4 (void *gptr);
37 ;
38 ;   void _gptrput  (void *ptr, unsigned char val);
39 ;   void _gptrput1 (void *ptr, unsigned char val);
40 ;   void _gptrput2 (void *ptr, unsigned int  val);
41 ;   void _gptrput3 (void *ptr, unsigned int  val);
42 ;   void _gptrput4 (void *ptr, unsigned long val);
43
44 include macros.inc
45 include p16f_common.inc
46
47         global  __gptrget2
48         extern  __codeptrget1
49         
50         CODE
51
52 __gptrget2:
53         select_routine __dataptrget2, __codeptrget2
54         ; invalid tag -- return 0x0000
55         clrf    STK00
56         retlw   0x00
57
58 __dataptrget2:
59         setup_fsr
60         movf    _INDF, W
61         movwf   STK00           ; low byte in STK00
62         inc_fsr
63         movf    _INDF, W        ; high byte in WREG
64         return
65
66 __codeptrget2:
67         pagesel __codeptrget1   ; might reside in different page
68         call    __codeptrget1
69         movwf   STK02           ; temporarily store LSB
70         incfsz  STK01,F ; increment low address byte
71         decf    STK00,F ; undo increment of high address byte if low byte did not overflow
72         incf    STK00,F ; increment high address byte
73         pagesel __codeptrget1   ; might reside in different page
74         call    __codeptrget1
75         movwf   STK03           ; temporarily store MSB
76         movf    STK02, W
77         movwf   STK00           ; LSB in STK00
78         movf    STK03, W        ; MSB in WREG
79         return
80         
81         END