projects
/
fw
/
sdcc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* configure,
[fw/sdcc]
/
device
/
lib
/
_divuint.c
diff --git
a/device/lib/_divuint.c
b/device/lib/_divuint.c
index 43a11ee4d2b17eaf1e3e202a9bdaf0ab2769f614..03b91998313be3276c678af1cc71470e141e56bd 100644
(file)
--- a/
device/lib/_divuint.c
+++ b/
device/lib/_divuint.c
@@
-27,6
+27,8
@@
mcs51 small stack-auto
*/
mcs51 small stack-auto
*/
+#include <stdbool.h>
+
#if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
# if defined(SDCC_mcs51)
# if defined(SDCC_MODEL_SMALL)
#if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
# if defined(SDCC_mcs51)
# if defined(SDCC_MODEL_SMALL)
@@
-53,36
+55,39
@@
_divuint_dummy (void) _naked
#define count r2
#define reste_l r3
#define reste_h r4
#define count r2
#define reste_l r3
#define reste_h r4
- #define al dpl
- #define ah dph
-
-#ifdef SDCC_STACK_AUTO
+ #define xl dpl
+ #define xh dph
- ar0 = 0 ; BUG register set is not considered
- ar1 = 1
+#if defined(SDCC_PARMS_IN_BANK1)
+ #define yl (b1_0)
+ #define yh (b1_1)
+#else // SDCC_PARMS_IN_BANK1
+ #if defined(SDCC_STACK_AUTO)
.globl __divint
mov a,sp
add a,#-2 ; 2 bytes return address
.globl __divint
mov a,sp
add a,#-2 ; 2 bytes return address
- mov r0,a ; r0 points to bh
- mov ar1,@r0 ; load bh
+ mov r0,a ; r0 points to yh
+ mov a,@r0 ; load yh
+ mov r1,a
dec r0
dec r0
- mov ar0,@r0 ; load bl
+ mov a,@r0 ; load yl
+ mov r0,a
- #define
b
l r0
- #define
b
h r1
+ #define
y
l r0
+ #define
y
h r1
__divint: ; entry point for __divsint
__divint: ; entry point for __divsint
-#else // SDCC_STACK_AUTO
+
#else // SDCC_STACK_AUTO
-#if defined(SDCC_NOOVERLAY)
+
#if defined(SDCC_NOOVERLAY)
.area DSEG (DATA)
.area DSEG (DATA)
-#else
+
#else
.area OSEG (OVR,DATA)
.area OSEG (OVR,DATA)
-#endif
+
#endif
.globl __divuint_PARM_2
.globl __divsint_PARM_2
.globl __divuint_PARM_2
.globl __divsint_PARM_2
@@
-93,22
+98,23
@@
_divuint_dummy (void) _naked
.area CSEG (CODE)
.area CSEG (CODE)
- #define
b
l (__divuint_PARM_2)
- #define
b
h (__divuint_PARM_2 + 1)
+ #define
y
l (__divuint_PARM_2)
+ #define
y
h (__divuint_PARM_2 + 1)
-#endif // SDCC_STACK_AUTO
+ #endif // SDCC_STACK_AUTO
+#endif // SDCC_PARMS_IN_BANK1
mov count,#16
clr a
mov reste_l,a
mov reste_h,a
mov count,#16
clr a
mov reste_l,a
mov reste_h,a
- loop: mov a,
al ; a
<<= 1
+ loop: mov a,
xl ; x
<<= 1
add a,acc
add a,acc
- mov
a
l,a
- mov a,
a
h
+ mov
x
l,a
+ mov a,
x
h
rlc a
rlc a
- mov
a
h,a
+ mov
x
h,a
mov a,reste_l ; reste <<= 1
rlc a ; feed in carry
mov a,reste_l ; reste <<= 1
rlc a ; feed in carry
@@
-117,18
+123,18
@@
_divuint_dummy (void) _naked
rlc a
mov reste_h,a
rlc a
mov reste_h,a
- mov a,reste_l ; reste -
b
- subb a,
b
l ; here carry is always clear, because
+ mov a,reste_l ; reste -
y
+ subb a,
y
l ; here carry is always clear, because
; reste <<= 1 never overflows
mov b,a
mov a,reste_h
; reste <<= 1 never overflows
mov b,a
mov a,reste_h
- subb a,
b
h
+ subb a,
y
h
- jc smaller ; reste >=
b
?
+ jc smaller ; reste >=
y
?
- mov reste_h,a ; -> yes; reste = reste -
b
;
+ mov reste_h,a ; -> yes; reste = reste -
y
;
mov reste_l,b
mov reste_l,b
- orl
a
l,#1
+ orl
x
l,#1
smaller: ; -> no
djnz count,loop
ret
smaller: ; -> no
djnz count,loop
ret
@@
-141,34
+147,30
@@
_divuint_dummy (void) _naked
#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
unsigned int
#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
unsigned int
-_divuint (unsigned int
a, unsigned int b
)
+_divuint (unsigned int
x, unsigned int y
)
{
unsigned int reste = 0;
unsigned char count = 16;
{
unsigned int reste = 0;
unsigned char count = 16;
- #if defined(SDCC_STACK_AUTO) || defined(SDCC_z80)
- char c;
- #else
- bit c;
- #endif
+ BOOL c;
do
{
do
{
- // reste:
a
<- 0;
- c = MSB_SET(
a
);
-
a
<<= 1;
+ // reste:
x
<- 0;
+ c = MSB_SET(
x
);
+
x
<<= 1;
reste <<= 1;
if (c)
reste |= 1;
reste <<= 1;
if (c)
reste |= 1;
- if (reste >=
b
)
+ if (reste >=
y
)
{
{
- reste -=
b
;
- //
a
<- (result = 1)
-
a
|= 1;
+ reste -=
y
;
+ //
x
<- (result = 1)
+
x
|= 1;
}
}
while (--count);
}
}
while (--count);
- return
a
;
+ return
x
;
}
#endif // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO
}
#endif // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO