- lp0: mov a,a0 ; a <<= 1
- add a,a0
- mov a0,a
- mov a,a1
- rlc a
- mov a1,a
- mov a,a2
- rlc a
- mov a2,a
- mov a,a3
- rlc a
- mov a3,a
-
- jc in_lp
- djnz count,lp0
-
- sjmp exit
-
- loop: mov a,a0 ; a <<= 1
- add a,a0
- mov a0,a
- mov a,a1
- rlc a
- mov a1,a
- mov a,a2
- rlc a
- mov a2,a
- mov a,a3
- rlc a
- mov a3,a
-
- in_lp: mov a,reste0 ; reste <<= 1
- rlc a ; feed in carry
- mov reste0,a
- mov a,reste1
- rlc a
- mov reste1,a
- mov a,reste2
- rlc a
- mov reste2,a
- mov a,reste3
- rlc a
- mov reste3,a
-
- mov a,reste0 ; reste - b
- subb a,b0 ; carry is always clear here, because
- ; reste <<= 1 never overflows
- mov a,reste1
- subb a,@r0 ; b1
- mov a,reste2
- inc r0
- subb a,@r0 ; b2
- mov a,reste3
- inc r0
- subb a,@r0 ; b3
- dec r0
- dec r0
-
- jc minus ; reste >= b?
-
- ; -> yes; reste -= b;
- mov a,reste0
- subb a,b0 ; carry is always clear here (jc)
- mov reste0,a
- mov a,reste1
- subb a,@r0 ; b1
- mov reste1,a
- mov a,reste2
- inc r0
- subb a,@r0 ; b2
- mov reste2,a
- mov a,reste3
- inc r0
- subb a,@r0 ; b3
- mov reste3,a
- dec r0
- dec r0
-
- orl a0,#1
-
- minus: djnz count,loop ; -> no
-
- exit: mov a,a3 ; prepare the return value
- ret
-
- _endasm ;
+lp0: mov a,x0 ; x <<= 1
+ add a,x0
+ mov x0,a
+ mov a,x1
+ rlc a
+ mov x1,a
+ mov a,x2
+ rlc a
+ mov x2,a
+ mov a,x3
+ rlc a
+ mov x3,a
+
+ jc in_lp
+ djnz count,lp0
+
+ sjmp exit
+
+loop: mov a,x0 ; x <<= 1
+ add a,x0
+ mov x0,a
+ mov a,x1
+ rlc a
+ mov x1,a
+ mov a,x2
+ rlc a
+ mov x2,a
+ mov a,x3
+ rlc a
+ mov x3,a
+
+in_lp: mov a,reste0 ; reste <<= 1
+ rlc a ; feed in carry
+ mov reste0,a
+ mov a,reste1
+ rlc a
+ mov reste1,a
+ mov a,reste2
+ rlc a
+ mov reste2,a
+ mov a,reste3
+ rlc a
+ mov reste3,a
+
+ mov a,reste0 ; reste - y
+ subb a,y0 ; carry is always clear here, because
+ ; reste <<= 1 never overflows
+ mov a,reste1
+ subb a,@r0 ; y1
+ mov a,reste2
+ inc r0
+ subb a,@r0 ; y2
+ mov a,reste3
+ inc r0
+ subb a,@r0 ; y3
+ dec r0
+ dec r0
+
+ jc minus ; reste >= y?
+
+ ; -> yes; reste -= y;
+ mov a,reste0
+ subb a,y0 ; carry is always clear here (jc)
+ mov reste0,a
+ mov a,reste1
+ subb a,@r0 ; y1
+ mov reste1,a
+ mov a,reste2
+ inc r0
+ subb a,@r0 ; y2
+ mov reste2,a
+ mov a,reste3
+ inc r0
+ subb a,@r0 ; y3
+ mov reste3,a
+ dec r0
+ dec r0
+
+ orl x0,#1
+
+minus: djnz count,loop ; -> no
+
+exit: mov a,x3 ; prepare the return value
+ ret
+
+ __endasm;