Register | Login
Forum Index > Bugs and Fixes > local variable error
Author Message
Pages: 1
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[714] local variable error - posted: 2011-11-16 20:43:26
this works fine , note well , right is global variable here
Code:
program WIN32CUI 'test';

#include 'console.zir';
#include 'zirutils.zir';

char right[5100];
dword indx;
char tmp[255];

   indx = 2;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   IntToStr(eax,@tmp);
   print(@tmp,'\r\n');  
   
   indx = 3;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   IntToStr(eax,@tmp);
   print(@tmp,'\r\n');  
wait_key(nil);
ExitProcess(0);              


but this does not work correctly , try compile the 2 examples and see the results
not well right is local variable here
Code:
program WIN32CUI 'test';

#include 'console.zir';
#include 'zirutils.zir';

procedure main()
{
char right[5100];
dword indx;
char tmp[255];

   indx = 2;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   IntToStr(eax,@tmp);
   print(@tmp,'\r\n');  
   
   indx = 3;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   IntToStr(eax,@tmp);
   print(@tmp,'\r\n');  
}

main();   
wait_key(nil);
ExitProcess(0);          


i think getting address of local variable has some problem.


http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[716] - posted: 2011-11-16 23:03:54
What is the problem? I do not have any error.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[717] - posted: 2011-11-16 23:07:19

ok , run the 2 code and compare the results , it is logical error.

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[718] - posted: 2011-11-16 23:13:15
ok i see.. it is because you are often using EAX ... too often :P

local variables called like so: @var, will use eax trashing the value... in your case:

Code:
   IntToStr(eax,@tmp);


this code here is destroyed before being pushed onto the stack.. so it produces something like:

Code:
lea eax, [ebp-...]
push eax
push eax
call ...


what you could do is...

Code:
ecx = @tmp;
IntToStr(eax, ecx);


which should produce:

Code:
lea ecx, [ebp-...]
push ecx
push eax
call ...


I will come up with a better solution for this in a newer version, once i finish the new lea handler smile

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[719] - posted: 2011-11-16 23:17:29
Code:
program WIN32CUI 'test';

#include 'console.zir';
#include 'zirutils.zir';

procedure main() {
  char right[5100];
  dword indx;
  char tmp[255];

   indx = 2;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   ecx = @tmp;
   IntToStr(eax,ecx);
   print(@tmp,'\r\n');  
   
   indx = 3;
      
   eax = indx
   imul  eax,255
   Edx = @right
   add eax,Edx
   push eax
   IntToStr(indx,@tmp);
   print(@tmp,'\r\n');
   pop eax
   ecx = @tmp;
   IntToStr(eax,ecx);
   print(@tmp,'\r\n');  
}

main();   
wait_key(nil);
ExitProcess(0);            


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[720] - posted: 2011-11-16 23:34:28
slightly better version:

Code:
program WIN32CUI 'test';

#include 'console.zir';
#include 'zirutils.zir';

procedure main() {
  char right[5100];
  dword indx;
  char tmp[255];

  indx = 2;
      
  eax = indx
  imul eax, 255
  edx = @right
  eax += edx;
  ecx = @tmp;
  IntToStr(indx, ecx);
  print(@tmp,'\r\n');   
  ecx = @tmp;
  IntToStr(eax, ecx);
  print(@tmp,'\r\n');  
   
  indx = 3;
      
  eax = indx
  imul eax, 255
  edx = @right
  eax += edx;
  ecx = @tmp;
  IntToStr(indx, ecx);
  print(@tmp,'\r\n');
  ecx = @tmp;
  IntToStr(eax,ecx);
  print(@tmp,'\r\n');  
}

main();   
wait_key(nil);
ExitProcess(0); 


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 7 user(s) online. 0 member(s) and 7 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd