flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Cleaning the stack

Author
Thread Post new topic Reply to topic
Andy



Joined: 17 Oct 2011
Posts: 26
Andy
Hi guys,

First of all I'm new to forum and beginer in assembler. I am using a high level language that support fasm inline. Actually I use fasm to generate some raw machine codes to improve the speed of my programs. I started for test with calling Beep function from kernel32.dll. The prototype is Beep(frequence,duration).

My code looks like that :
Code:
0x
68 E8 03             ;push 1000 - duration
68 E8 03             ;push 1000 - frequence
B8 FF 79 83 7C       ;mov eax, address of Beep function (I get this in high level, it's not 7C8379FF, this is just example)
FF D0                ;call eax
C3                   ;ret    


can someone help me to understand how to clean the stack for cdecl call convention?
Thanks in advance!


Last edited by Andy on 03 Nov 2011, 20:32; edited 3 times in total
Post 18 Oct 2011, 12:49
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello,
With cdecl calling convention you must clean up the stack in this way :
Code:
push a
push b
call function name
add esp, size*2                       ; size  * number of arguments( if you use 32 bit 4*2)
    

For stdcall you do not have to clean the stack:
Code:
push a
push b
push c
call function name
    
Wink

_________________
Nil Volentibus Arduum Razz
Post 18 Oct 2011, 13:18
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 695
Location: Adelaide
sinsi
Those 66s look a bit strange, that's a size override. Not pushing dwords?
Post 18 Oct 2011, 13:34
View user's profile Send private message Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 26
Andy
yes, freq and duration are dwords, I used wrong opcodes?
Post 18 Oct 2011, 13:43
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
yes, freq and duration are dwords, I used wrong opcodes?

Yes Razz
what language are you using?
C language ?
Java ?
Visual Basic ?
Code:
68 00 10                        ; push 1000
68 00 10                        ; push 1000
B8 FF 79 83 7C                   ; mov eax,7c8379ff
FF D8                             ; call eax
C3                               ; ret
    

_________________
Nil Volentibus Arduum Razz
Post 18 Oct 2011, 13:49
View user's profile Send private message Reply with quote
Andy



Joined: 17 Oct 2011
Posts: 26
Andy
auch, it's my fault, I typed wrong it's 68 in my example. I am using AutoIt. Thanks for your help guys, seems I made many mistakes today, actually my error wasn't in this raw code, but anyway I learn something: to clean up the stack. I have just one more question, where I can find some good beginers FASM tutorials?
Post 18 Oct 2011, 14:01
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
I am using AutoIt
Shocked

Quote:
where I can find some good beginers FASM tutorials


http://flatassembler.net/docs.php Wink

_________________
Nil Volentibus Arduum Razz
Post 18 Oct 2011, 14:14
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.