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
I discovered another bug in UM/MOD and solved it. The udh part of the dividend must be smaller than the divisor to get the correct quotient but the original version was accepting udh==un to solve this bug I replaced JRULE for the overflow test by JRULT. the modified code is:
UMMOD:
PUSHW X ; save stack pointer
LDW X,(X) ; un
LDW YTEMP,X ; save un
LDW Y,(1,SP) ; X stack pointer
LDW Y,(4,Y) ; Y=udl
LDW X,(1,SP) ; X
LDW X,(2,X) ; X=udh
CPW X,YTEMP
JRULT MMSM1 ; udh must be < un to avoid overflow
; division overflow return q=0,r=-1
POPW X
INCW X ; pop off 1 level
INCW X ; ADDW X,#2
LDW Y,#0xFFFF
LDW (X),Y
CLRW Y
LDW (2,X),Y
RET
MMSM1:
LD A,#17 ; loop count
MMSM3:
CPW X,YTEMP ; compare udh to un
JRULT MMSM4 ; can't subtract
MMSMa:
SUBW X,YTEMP ; can subtract
RCF
MMSM4:
CCF ; quotient bit
RLCW Y ; rotate into quotient
RLCW X ; rotate into remainder
DEC A ; repeat
JREQ MMSMb ; if A == 0
JRC MMSMa ; if carry out of rotate
JRA MMSM3 ;
MMSMb:
RRCW X
LDW YTEMP,X ; done, save remainder
POPW X
INCW X ; drop
INCW X ; ADDW X,#2
LDW (X),Y
LDW Y,YTEMP ; save quotient
LDW (2,X),Y
RET
The text was updated successfully, but these errors were encountered:
MrMarkB
added a commit
to MrMarkB/stm8ef
that referenced
this issue
Feb 8, 2021
Addresses UM/MOD issues including not accounting for carry out in shift operation for quotient and remainder (TG9541#400) and issue with compare on overflow checking (TG9541#401).
I discovered another bug in UM/MOD and solved it. The udh part of the dividend must be smaller than the divisor to get the correct quotient but the original version was accepting udh==un to solve this bug I replaced JRULE for the overflow test by JRULT. the modified code is:
The text was updated successfully, but these errors were encountered: