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: 932
Topics: 54

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: 932
Topics: 54

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: 932
Topics: 54

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: 932
Topics: 54

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 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 999, May 11, 2018, 10:01 am.


Statistics:
Threads: 224 | Posts: 1847 | Members: 50 | Active Members: 50
Welcome to our newest member, NobodyAtWork
const Copyright = '2011-2021 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd