flat assembler
Message board for the users of flat assembler.

Index > Windows > local variable doesn't work, but global works in proc

Author
Thread Post new topic Reply to topic
sleepsleep



Joined: 05 Oct 2006
Posts: 8999
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
i am trying to use local variables (wc:WNDCLASSEX) inside the proc.

eg.
Code:
proc WinMain hinst, hprevinst, lpcmdline, ncmdshow
local wc:WNDCLASSEX
             mov     [wc.cbSize],sizeof.WNDCLASSEX
               mov     [wc.style],CS_HREDRAW + CS_VREDRAW
          mov     [wc.lpfnWndProc],WindowProc
         mov     [wc.cbClsExtra],NULL
                mov     [wc.cbWndExtra],NULL
                push    [hinstance]
         pop     [wc.hInstance]
              mov     [wc.hbrBackground],COLOR_WINDOW+1
           mov     [wc.lpszMenuName],NULL
              mov     [wc.lpszClassName],clsname
  invoke  LoadIcon,NULL,IDI_APPLICATION
               mov     [wc.hIcon],eax
      invoke  LoadCursor,NULL,IDC_ARROW
           mov     [wc.hCursor],eax
    invoke  RegisterClassEx,wc
          ret
endp
    

assembled with error

Code:
        invoke  RegisterClassEx,wc
D:\fasm\include\win32ax.inc [41] invoke [0]:
  \{ \reverse pushd <arg>
D:\fasm\include\win32ax.inc [37] pushd [27]:
      pushd <value>
D:\fasm\include\win32ax.inc [113] pushd [41]:
    push value
error: invalid value.
    

if i change the wc WNDCLASSEX as global variable, it assemble without problem.

so, is that i shouldn't use WNDCLASSEX as local variable inside a proc?

i tried

Code:
locals
wc WNDCLASSEX
endl
    

same error output too.
Post 14 Aug 2009, 19:24
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Replace the line with "invoke RegisterClassEx, addr wc".
Post 14 Aug 2009, 19:34
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Small explanation: address of local variable cannot be calculated at compile-time (addresses of globals can be), so you must tell FASM (actually, pushd macro) that you want to calculate this address at runtime.
Code:
invoke sth, addr foo    
generates the following
Code:
lea edx, foo ;although I'm not sure about used register
push edx
call [sth]    


Last edited by Fanael on 14 Aug 2009, 21:11; edited 2 times in total
Post 14 Aug 2009, 20:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
It is all explained here: http://flatassembler.net/docs.php?article=win32

Quote:

(address of global can be, as long as executable doesn't have relocations)

Just a small note, even with relocations you will still be able to use "mov reg, some_global", because the executable loader will adjust the immediate operand to point to the actual location.
Post 14 Aug 2009, 20:48
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Ahhh, yes... I was led astray by erros like this one:
Code:
if $ mod 2 = 0 ;suprise!
;...
end if
;...
section '.reloc' fixups readable discardable    
Anyway, thanks for correction.
Post 14 Aug 2009, 21:15
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8999
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
thanks guys !! Smile appreciated.
Post 16 Aug 2009, 04:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.