flat assembler
Message board for the users of flat assembler.

Index > Windows > Stack frames

Author
Thread Post new topic Reply to topic
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 30 Apr 2004, 16:11
Hi everyone!

Code:
include "win32ax.inc"

.data

        sTemp db "Test!",0

.code

        start:
                stdcall xproc_ok,sTemp
                stdcall xproc_error,sTemp
                invoke  ExitProcess,0

        xproc_ok:
                push    ebp
                mov     ebp,esp
                sub     esp,0Ch
                mov     word [ebp-0Ch],0078h
                push    0
                lea     eax,[ebp-0Ch]
                push    eax
                push    dword [ebp+8]
                push    0
                call    [MessageBox]
                leave
                ret     4

        xproc_error:
                push    ebp
                mov     ebp,esp
                sub     esp,0Ah
                mov     word [ebp-0Ah],0078h
                push    0
                lea     eax,[ebp-0Ah]
                push    eax
                push    dword [ebp+8]
                push    0
                call    [MessageBox]
                leave
                ret     4

.end start    
I don't know whether or not this is a dumb question, but anyway... I'm trying to get more knowledge to stack frames (since I'm working on a compiler)... Why is "xproc_ok" working and not "xproc_error"? The only difference is that in the first mentioned I've "allocated" 12 bytes of local data, and in the second "only" 10... What's the problem? Is there something I've been missing?? Confused Embarassed

(The error I get is that the MessageBox isn't shown properly in the other procedure... I'm using WinXP)...

Thanks! Any help is appreciated!

Best regards,
Tommy
Post 30 Apr 2004, 16:11
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 30 Apr 2004, 16:24
I'm not sure, but it seems that the stack pointer should be 4-byte aligned. In real (16-bit) mode it should work ok). In 32-bit you should align to dword anything that you put on the stack. I'm not exactly sure why, but it is Very Happy
Post 30 Apr 2004, 16:24
View user's profile Send private message Visit poster's website Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv 30 Apr 2004, 17:02
I think decard is right. The stack should be aligned to dword as far as possible.
Post 30 Apr 2004, 17:02
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Apr 2004, 20:03
in docs it is writen exactly as decard and roticv told: stack SHOULD be aligned to dword. Nothing about why / what happens if not (of course that some extra processor clocks are taken, but no reason for bug).

Stack is very dangerous to play with (or use in some slightly instandard) under windoze.

just some note: stack aligning is nicely done with "and" instruction:
Code:
and esp,align_size - 1
    
Post 30 Apr 2004, 20:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 01 May 2004, 06:33
Thanks! Very Happy I was thinking about the same before I fell to sleep yesterday, but I was not sure... Thanks again!

/Tommy
Post 01 May 2004, 06:33
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 01 May 2004, 10:09
Well, thanks guys... That problem is now fixed... May I ask you for another favour? Confused Can someone help me debug the attached program Embarassed (no asm code included since this file was produced by my compiler)... Thanks!

(The bug occurs while registering the window class)...

Sorry if this is a bit off-topic, but... Sad

/Tommy


Description: Buggy program...
Download
Filename: OOP.zip
Filesize: 3.24 KB
Downloaded: 338 Time(s)

Post 01 May 2004, 10:09
View user's profile Send private message Visit poster's website Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv 01 May 2004, 12:12
If you ask me, your code is wrong...

I think it should be

if (RegisterClass(wc)==0) {
ShowError("Could not register window class!");
}
Post 01 May 2004, 12:12
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 01 May 2004, 13:45
It is... Embarassed My fault... But when I correct it... It doesn't help... The class is obviously not registered properly.... See attachment... Confused


Description: Still buggy
Download
Filename: OOP.zip
Filesize: 3.12 KB
Downloaded: 340 Time(s)

Post 01 May 2004, 13:45
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 01 May 2004, 14:03
Forget it... I solved the problem... Thanks anyway! Thanks for all help! Very Happy

Cheers,
Tommy
Post 01 May 2004, 14:03
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 12 May 2004, 11:06
Hi again guys!

Once again I have a problem related to the Win32 PE format... Why doesn't the attached executable work?? Confused Sad (I've also attached the source codes, not ASM, but sources for my own compiler... They won't help for solving the bug...) If anybody can help me, please! Sad (I know it's a bit off-topic...but...) Thanks!

Regards,
Tommy


Description: Buggy app - trying to execute Notepad with ShellExecute in SHELL32.DLL" (work if I write it in FASM, but not in my compiler... bug in the PE formatter I guess... :()
Download
Filename: TestApp.zip
Filesize: 865 Bytes
Downloaded: 346 Time(s)

Post 12 May 2004, 11:06
View user's profile Send private message Visit poster's website Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv 12 May 2004, 11:12
Doesn't work as in? It does work on my win2k though.
Post 12 May 2004, 11:12
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 12 May 2004, 12:44
Hmm.. Confused Not on XP... Sad
Post 12 May 2004, 12:44
View user's profile Send private message Visit poster's website 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.