V2.50 DWord var params calculation problem [solved]

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

V2.50 DWord var params calculation problem [solved]

#1 Post by Dany » 23 Aug 2009 14:00

Hi, I have some unexpected results in the following code example.

The calculation of "Mod_" in procedure "DivMod" gives a wrong result in "Mod_" (should be 272) and spoils at the same time the content of variable "Div_" that was correct just before.

See comment in the source code for details.

Thanks in advance! :D

Code: Select all

program PowersOf2;

{ Declarations section }

var Value_, Tmp1, Res1, Res2: Dword;

    
function PowerOf(Value: DWord): word;
var Tmp: word;
begin
  Tmp := 0;
  while Dword(1 shl Tmp) < Value do inc(Tmp);
  Result := Tmp;
end;

procedure DivMod(Val_, Divider: DWord; var Div_, Mod_: Dword);
var Power: word;
begin
  Power := PowerOf(Divider);  // Power = 9 as expected
  Div_ := Val_ shr Power;     // Div_ is 19 as expected
  Mod_ := Div_ shl Power;     // Mod_ is 9728 as expected
  Mod_ := Val_ - Mod_;  // <----- here it goes wrong, >both< var params "Div_" and "Mod_" are messed up
end;
    
begin
  { Main program }
  
  Value_ := 512;
  Tmp1 := 10000;
  DivMod(Tmp1, Value_, Res1, Res2);
  
end.
Last edited by Dany on 24 Apr 2011 13:20, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: V2.50 DWord var params calculation problem

#2 Post by zristic » 25 Aug 2009 13:13

The version which is getting ready for release does not suffer from this bug, which means it is solved in the meantime.
Thanks.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: V2.50 DWord var params calculation problem

#3 Post by Dany » 25 Aug 2009 19:42

zristic wrote:The version which is getting ready for release does not suffer from this bug, which means it is solved in the meantime.
Thanks.
Great! Thanks! :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#4 Post by Dany » 22 Sep 2009 19:50

Confirmed solved in v3.00 bèta! :D :D Thanks!
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”