Register | Login
Forum Index > Bugs and Fixes > global variable redeclared
Author Message
Pages: 1 2 3
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1525] global variable redeclared - posted: 2015-01-27 18:56:29
Cannot compile this:
Code:
program RAW_IMAGE 'test';
  
#set bits 32;

dword a, b;

procedure MyProc() {
  dword a, b;
  a = b;
}

MyProc();


But was compiled when i commented first Code:
dword a, b;
.

Also after that i noticed that in generated raw binary MyProc looks:
Code:
00000005  55                push ebp
00000006  8BEC              mov ebp,esp
00000008  81EC08000000      sub esp,0x8
0000000E  FF75F8            push dword [ebp-0x8]
00000011  8F45FC            pop dword [ebp-0x4]
00000014  83C408            add esp,byte +0x8
00000017  C9                leave
00000018  C3                ret


Seems that you use Code:
add esp,byte +0x8
to restore stack.
But it can be done also with Code:
mov esp,ebp

But you already use Code:
leave

Next, i give quote from AMD Manual:

LEAVE

Releases a stack frame created by a previous ENTER instruction. To release the frame, it copies the
frame pointer (in the rBP register) to the stack pointer register (rSP), and then pops the old frame
pointer from the stack into the rBP register, thus restoring the stack frame of the calling procedure.
The 32-bit LEAVE instruction is equivalent to the following 32-bit operation:

MOV ESP,EBP
POP EBP
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1526] - posted: 2015-01-27 19:29:16
The CPU mode should offer this optimisation, the add esp is actually for local variables, where-as leave is for the stack parameters on call.

try

Code:
#set cpu 686;


I will also confirm if this is working correctly, if not I will take a look and correct this.

As for global variable, this is because your variable is already declared and you are trying to use the same identifier for the local variable..... I could make it so that they can be redeclared, but it was an intended functionality.

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:
[1527] - posted: 2015-01-27 19:47:35
Invalid directive operand cpu

the add esp is actually for local variables, where-as leave is for the stack parameters on call.
I do not understand why you think that it need. I think that just should remove Code:
add esp,byte +0x8
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1528] - posted: 2015-01-27 19:56:37
Also, just to let you knew, in this our case we can code esp -= 8; as:
Code:
83EC08            sub esp,byte +0x8
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1529] - posted: 2015-01-27 21:42:52
Sorry I misunderstood, you're right, the final add is not needed with stack frame, I will correct this.

It seems set cpu mode is also not working, I will also fix this.

Thanks.

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:
[1602] - posted: 2015-02-03 14:31:22
I think it is relevant to this topic.

Code:
program RAW_IMAGE 'test';

#set bits 32;

const a = 0;

procedure proc1(){
  const a = 1;
}

Unexpected number 0

Is it supported local constants or not? It would be more convinient smile
Also local variables still not supported.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1605] - posted: 2015-02-03 15:57:04
hmm... strange

This compile -- OK:
Code:
program RAW_IMAGE 'test';

#set bits 32;

//dword i;

procedure proc1(){
  dword i; i = 100500;
  while (i <> 0) {i--;}
}
procedure proc2(){
  dword i; i = 100500;
  while (i <> 0) {i--;}
}
procedure proc3(){
  procedure proc4(){
    procedure proc5(){
      dword i; i = 100500;
      while (i <> 0) {i--;}
    }  
    dword i; i = 100500;
    while (i <> 0) {i--;}
    proc5();
  }
  dword i; i = 100500;
  while (i <> 0) {i--;}
  proc4();
}

proc1(); proc2(); proc3();

But if uncomment global
Code:
//dword i;

then cannot compile.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1608] - posted: 2015-02-03 16:40:36
local constants are possible.

Code:
program RAW_IMAGE 'test';

#set bits 32;

const a = 0;

procedure proc1(){
  const a = 1;
}


In this case, you are writing const 0 = 1 because you already declared a as 0 and since it is a global const, it can be accessed from anywhere.

As for the second problem, global variables can not be redeclared right now. I may consider to make this possible in one of the following releases.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1 2 3
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 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