You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
;
;
;
.export __xdivequc
.export __xremequc
;
; (0,X) = (0,X) / B unsigned
;
__xremequc:
ldaa 0,x ; check dividend sign
jsr div8x8 ; B = A / B , A:remainder
tab
stab 0,x ; return B and 0,X as remainder
rts
;
; (0,X) = (0,X)/B unsigned
;
__xdivequc:
ldaa 0,x ; check diviend sign
jsr div8x8 ; B = A / B, A: remainder
stb 0,x ; return B and 0,X as quotient
rts
support6800/__xdiveqc.s
;
; (0,X) = (0,X) / B signed
;
; The rules for signed divide are
; Dividend and remainder have the same sign
; Quotient is negative if signs disagree
;
; So we do the maths in unsigned then fix up
;
.export __xdiveqc
.export __xremeqc
;
; The sign of the remainder of a division is not defined until C99.
; C99 says it's the sign of the dividend.
;
__xremeqc:
ldaa 0,x ; check dividend sign
bpl xremeqc_0
nega ; make dividend positive
xremeqc_0:
tstb ; check divisor sign
bpl xremeqc_1
negb ; make divisor positive
xremeqc_1:
jsr div8x8 ; B = A / B , A:remainder
tab
ldaa 0,x ; check dividend sign bit
bpl xremeqc_2
negb ; remainder has the same sign as the dividend
xremeqc_2:
stab 0,x ; return B and 0,X as remainder
rts
;
; (0,X) = (0,X)/B signed
;
; The sign of the result is positive if the inputs have the same
; sign, otherwise negative
;
__xdiveqc:
ldaa 0,x ; check diviend sign
bpl xdiveqc_0
nega ; make dividend positive
xdiveqc_0:
tstb ; check divisor sign
bpl xdiveqc_1
negb ; make divisor positive
com 0,x ; To reduce the size, use 0,X as the sign flag.
xdiveqc_1:
jsr div8x8 ; B = A / B, A: remainder
ldaa 0,x ; check sign flag
bpl xdiveqc_2
negb ; if signs disagree, negate quotient
xdiveqc_2:
stb 0,x ; return B and 0,X as quotient
rts
test program:
int main(int argc, char **argv)
{
signed char a,b;
unsigned char c,d;
a = 127;
a /= -128;
if (a!=0)
return 1;
a = -128;
a /= -128;
if (a!=1)
return 2;
b = -128;
b /= -128;
if (b!=1)
return 3;
b = 127;
b /= -128;
if (b!=0)
return 4;
b = 127;
b /= -1;
if (b!=-127)
return 5;
b = -128;
b /= -1;
if (b!=-128)
return 6;
c = 127;
c /= 128;
if (c!=0)
return 11;
c = 128;
c /= 128;
if (c!=1)
return 12;
d = 128;
d /= 128;
if (d!=1)
return 13;
d = 127;
d /= 128;
if (d!=0)
return 14;
d = 255;
d /= 127;
if (d!=2)
return 15;
d = 255;
d /= 1;
if (d!=255)
return 16;
a = 127;
a %= -128;
if (a!=127)
return 21;
a = -128;
a %= -128;
if (a!=0)
return 22;
b = -128;
b %= 49;
if (b!=-30)
return 23;
b = 127;
b %= -128;
if (b!=127)
return 24;
b = 127;
b %= -1;
if (b!=0)
return 25;
b = -128;
b %= -1;
if (b!=0)
return 26;
c = 127;
c %= 128;
if (c!=127)
return 31;
c = 128;
c %= 128;
if (c!=0)
return 32;
d = 128;
d %= 127;
if (d!=1)
return 33;
d = 127;
d %= 49;
if (d!=29)
return 34;
d = 255;
d %= 127;
if (d!=1)
return 35;
d = 255;
d %= 1;
if (d!=0)
return 36;
return 0;
}
The text was updated successfully, but these errors were encountered:
Will look into this once all the byte conversion stuff is actually behaving itself and it makes sense to do this on processors where we are doing byte conversions (eg 6502 as well)
support6800/divide8x8.s
support6800/__xdivequc.s
support6800/__xdiveqc.s
test program:
The text was updated successfully, but these errors were encountered: