Register | Login
Forum Index > Bugs and Fixes > Nested procedures problem
Author Message
Pages: 1
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1505] Nested procedures problem - posted: 2015-01-22 11:29:08
At first code without problems:
Code:
program RAW_IMAGE 'test';

#set bits 32;

procedure p0(){
  procedure p1(){
    procedure p2(){
      procedure p3(){
        procedure p4(){
          eax = 0x0FEDCBA9;       
        }
        p4();              
      }
      p3();          
    }
    p2();  
  }
  p1();
}
p0(); 


Output seems correct:
Code:
00000000  E800000000        call dword 0x5
00000005  55                push ebp
00000006  8BEC              mov ebp,esp
00000008  E802000000        call dword 0xf
0000000D  C9                leave
0000000E  C3                ret
0000000F  55                push ebp
00000010  8BEC              mov ebp,esp
00000012  E802000000        call dword 0x19
00000017  C9                leave
00000018  C3                ret
00000019  55                push ebp
0000001A  8BEC              mov ebp,esp
0000001C  E802000000        call dword 0x23
00000021  C9                leave
00000022  C3                ret
00000023  55                push ebp
00000024  8BEC              mov ebp,esp
00000026  E802000000        call dword 0x2d
0000002B  C9                leave
0000002C  C3                ret
0000002D  55                push ebp
0000002E  8BEC              mov ebp,esp
00000030  B8A9CBED0F        mov eax,0xfedcba9
00000035  C9                leave
00000036  C3                ret



Next, comment call to p1(); in p0 procedure:
Code:
program RAW_IMAGE 'test';

#set bits 32;

procedure p0(){
  procedure p1(){
    procedure p2(){
      procedure p3(){
        procedure p4(){
          eax = 0x0FEDCBA9;       
        }
        p4();              
      }
      p3();          
    }
    p2();  
  }
//  p1();
}
p0();


Output was only this:
Code:
00000000  E800000000        call dword 0x5
00000005  55                push ebp
00000006  8BEC              mov ebp,esp
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1506] - posted: 2015-01-22 13:55:55
Thanks for report, fixed for next release.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1749] - posted: 2015-02-20 19:24:55
Code:
program RAW_IMAGE 'test';
#set bits 32;
procedure X1(){
  inline procedure X2(){
    int3;
  }
}
X2();
It compiles successfully. But I think that there should not compile. Because X2 in X1 scope.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1765] - posted: 2015-02-23 12:32:14
Fixed for next release, was an major issue with scope related to macros. Thanks for report.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1847] - posted: 2016-05-03 11:06:32
Seems this work incorrect: Code:
program PE32_CUI 'Test';
#include 'console.zir';

procedure p0(dword count){
  dword y; y = 100500;
  procedure p1(dword x, count){
    if (count <> 0){
      println x;
      count--;
      p1(y, count);
    }
  }
  p1(y, count);
}
p0(10);

wait_key();
ExitProcess(0);

100500
9
8
7
6
5
4
3
2
1
Press any key to continue
And pay attention that the LEVEL of NESTING may be deeper
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1870] - posted: 2016-12-18 22:16:31
After some careful consideration, I've decided not to fix this and instead remove access to local variables outside the sub function scope, instead they should be passed to the sub function.

Several reasons made me come to this decision, the first is that automatically, the base function would need to push the stack pointer to the sub function and for sub-sub functions would require 2 pushed stack pointers, this is extremely inefficient, and I would never advise anyone programs like this.

The sub functions work great as a way of simplifying a function. As for your code, you just need to replace in your recursive p1 call to "x" instead of "y".

Code:
procedure p0(dword count){
  dword y; y = 100500;
  
  procedure p1(dword x, cnt){
    if (cnt <> 0){
      println x;
      cnt--;
      p1(x, cnt);
    }
  }
  
  p1(y, count);
}
p0(10);


I'm not sure I understand the purpose of this procedure, I guess it is just an example.

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 3 user(s) online. 0 member(s) and 3 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