flat assembler
Message board for the users of flat assembler.

Index > Windows > invoke [local variable] compile error

Author
Thread Post new topic Reply to topic
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 12 Apr 2010, 21:38
What am I doing wrong here? (win32wxp.inc)

Code:
proc main
 locals
  ...
  hfile           rd 1
  ... 
 endl      


Code:
mov     [hfile],eax

invoke  GetFileSize,[hfile],filesizeh ;<-- Error: invalid value (push ..var?QU)    


Worked when it was global.

_________________
This is a block of text that can be added to posts you make.
Post 12 Apr 2010, 21:38
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Apr 2010, 21:54
Is "filesizeh" also local? In that case use "addr filesizeh" instead.

[edit]This works:
Code:
include 'win32axp.inc'

proc main
 locals
  hfile           rd 1
  filesizeh       rd 1
 endl

 invoke GetFileSize, [hfile], addr filesizeh
 ret
endp

.end main    
[/edit]
Post 12 Apr 2010, 21:54
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 12 Apr 2010, 23:46
Yes, that makes it work. Remind me, why is addr needed here? Now that you mention it I have seen similar threads around here. Is it needed to explicitly produce lea instructions?
Post 12 Apr 2010, 23:46
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Apr 2010, 00:24
Because if you don't use addr you'll get "push ebp+offset", and the processor does not support that. With global vars this problem does not occur because the address ends up being a single number so the "push imm32" instruction can be used there.

And yes, "addr" (which use "lea edx, [argument] / push edx") has to be explicitly specified (and you also have to be aware that EDX is obviously destroyed in the process so you have to be careful if you use it as an argument).
Post 13 Apr 2010, 00:24
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 13 Apr 2010, 03:07
In short: Local variables are stored on the local stack frame.
Post 13 Apr 2010, 03:07
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 13 Apr 2010, 08:26
OK, thanks, I can buy that I need to make it explicit because I need to be aware of that edx gets clobbered. The error message was a bit hard to interpret Smile
Post 13 Apr 2010, 08:26
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.