Gast
#1679334
Hallo µC Gemeinde, hab in nem controller ne dividier routine laufen sie soll eine 24 bit konstante (3 000 000) durch eine variable teilen, das problem ist das sie ab einer variablen um 47 000 mist berechnet... die routine ist eine atmel apnote, nur auf 24 bit verändert durch das hinzufügen von rol dd16uM. kennt jemand solch ein verhalten? lg flo div16u: clr drem16uL ;clear remainder Low byte sub drem16uH,drem16uH ;clear remainder High byte and carry ldi dcnt16u,25 ;init loop counter d16u_1: rol dd16uL ;shift left dividend rol dd16uM rol dd16uH dec dcnt16u ;decrement counter brne d16u_2 ;if done ret ;return d16u_2: rol drem16uL ;shift dividend into remainder rol drem16uH sub drem16uL,countl ;remainder = remainder - divisor sbc drem16uH,counth ; brcc d16u_3 ;if result negative add drem16uL,countl ;restore remainder adc drem16uH,counth clc ;clear carry to be shifted into result rjmp d16u_1 ;else d16u_3: sec ;set carry to be shifted into result rjmp d16u_1