Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Calling conventions...

shaolin007shaolin007 Member Posts: 1,018
[green]

If I'm going to import C functions into assembly I guess I need to be familiar with the _cdecl right?

Could someone give me a quick overview of it. From what I understand, it says parameters are pushed right->left and the caller cleans up the stack? Is this right?
[/green]



Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [green]
    :
    : If I'm going to import C functions into assembly I guess I need to be familiar with the _cdecl right?
    :
    : Could someone give me a quick overview of it. From what I understand, it says parameters are pushed right->left and the caller cleans up the stack? Is this right?
    : [/green]
    :
    :
    :
    :
    [blue]That's one good source:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_Calling_Conventions_Topics.asp
    [/blue]
  • shaolin007shaolin007 Member Posts: 1,018
    : : [green]
    : :
    : : If I'm going to import C functions into assembly I guess I need to be familiar with the _cdecl right?
    : :
    : : Could someone give me a quick overview of it. From what I understand, it says parameters are pushed right->left and the caller cleans up the stack? Is this right?
    : : [/green]
    : :
    : :
    : :
    : :
    : [blue]That's one good source:
    :
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_Calling_Conventions_Topics.asp
    : [/blue]
    :

    [green]
    So in the case of _cdecl, it is the caller that cleans up the stack while in the _stdcall the called function cleans up the stack? Am I reading that right?
    [/green]

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : : : [green]
    : : :
    : : : If I'm going to import C functions into assembly I guess I need to be familiar with the _cdecl right?
    : : :
    : : : Could someone give me a quick overview of it. From what I understand, it says parameters are pushed right->left and the caller cleans up the stack? Is this right?
    : : : [/green]
    : : :
    : : :
    : : :
    : : :
    : : [blue]That's one good source:
    : :
    : : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_Calling_Conventions_Topics.asp
    : : [/blue]
    : :
    :
    : [green]
    : So in the case of _cdecl, it is the caller that cleans up the stack while in the _stdcall the called function cleans up the stack? Am I reading that right?
    : [/green]
    :
    :
    [blue]Correct.[/blue]
  • shaolin007shaolin007 Member Posts: 1,018
    : : : : [green]
    : : : :
    : : : : If I'm going to import C functions into assembly I guess I need to be familiar with the _cdecl right?
    : : : :
    : : : : Could someone give me a quick overview of it. From what I understand, it says parameters are pushed right->left and the caller cleans up the stack? Is this right?
    : : : : [/green]
    : : : :
    : : : :
    : : : :
    : : : :
    : : : [blue]That's one good source:
    : : :
    : : : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_Calling_Conventions_Topics.asp
    : : : [/blue]
    : : :
    : :
    : : [green]
    : : So in the case of _cdecl, it is the caller that cleans up the stack while in the _stdcall the called function cleans up the stack? Am I reading that right?
    : : [/green]
    : :
    : :
    : [blue]Correct.[/blue]
    :
    [green]
    Ok, now I think I can start importing some C functions into my assembly and start on Windows programming.
    [/green]



  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [green]
    : Ok, now I think I can start importing some C functions into my assembly and start on Windows programming.
    : [/green]

    [blue]FASM rules for Win32 coding! :-)[/blue]
  • shaolin007shaolin007 Member Posts: 1,018
    [b][red]This message was edited by shaolin007 at 2005-5-18 7:2:50[/red][/b][hr]
    : : [green]
    : : Ok, now I think I can start importing some C functions into my assembly and start on Windows programming.
    : : [/green]
    :
    : [blue]FASM rules for Win32 coding! :-)[/blue]
    :
    [green]
    I'm going to probably use that and I hope it's very similiar to NASM.
    Also from what I understand, Windows API follow the _stdcall convention when you call thier functions? So that would mean I wouldn't have to clean up the stack afterwards right?

    [code]
    jmp Winmain

    hwnd dd 0
    caption db "This is my MessageBox title",0
    text db "This is text in my MessageBox",0
    utype dd MB_ICONASTERISK

    Winmain:

    push utype
    push text
    push caption
    push hwnd
    call MessageBox

    ;after call no need to correct stack
    [/code]


    Last thing, with this Windows function I would have to use the winuser.h and import the library user32.lib for this to work with an assembler? Another thing, I would have to check the return value through the register eax? The win32.hlp file doesn't specify that or I don't see where it does. Sorry about all the questions just still learning. :-)
    [/green]




  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [b][red]This message was edited by shaolin007 at 2005-5-18 7:2:50[/red][/b][hr]
    : : : [green]
    : : : Ok, now I think I can start importing some C functions into my assembly and start on Windows programming.
    : : : [/green]
    : :
    : : [blue]FASM rules for Win32 coding! :-)[/blue]
    : :
    : [green]
    : I'm going to probably use that and I hope it's very similiar to NASM.
    : Also from what I understand, Windows API follow the _stdcall convention when you call thier functions? So that would mean I wouldn't have to clean up the stack afterwards right?
    :
    : [code]
    : jmp Winmain
    :
    : hwnd dd 0
    : caption db "This is my MessageBox title",0
    : text db "This is text in my MessageBox",0
    : utype dd MB_ICONASTERISK
    :
    : Winmain:
    :
    : push utype
    : push text
    : push caption
    : push hwnd
    : call MessageBox
    :
    : ;after call no need to correct stack
    : [/code]
    :
    :
    : Last thing, with this Windows function I would have to use the winuser.h and import the library user32.lib for this to work with an assembler? Another thing, I would have to check the return value through the register eax? The win32.hlp file doesn't specify that or I don't see where it does. Sorry about all the questions just still learning. :-)
    : [/green]
    :
    [blue]Those are all good questions!
    Check out the tutorials from here:

    http://spiff.tripnet.se/~iczelion/tutorials.html

    These are the best!

    Now, about questions:

    The call is absolutely correct. No need to clean up after Win32 API functions - nice thing!

    The only thing I do not get is why to jump over the data. The data should be in its own section, and the code should be in its own section. The code starts execution at the label which follows the END statement, just like in DOS programming:
    [code]
    main:

    ...

    END main
    [/code]
    Maybe, in NASM it is different. Never tried NASM.

    Now, you do not need any .H files, from C/C++ programming, so no need for this WINUSER.H file, just maybe import that USER32.LIB.

    Again, no idea how it is done in NASM, but in FASM - you simply hook the functions you need with a very simple macro statement. Check it out - it is very easy! And in FASM - no need to link anything - you get your EXE file right there - from the ASM file![/blue]
  • shaolin007shaolin007 Member Posts: 1,018
    [red]
    : The only thing I do not get is why to jump over the data. The data should be in its own section, and the code should be in its own section. The code starts execution at the label which follows the END statement, just like in DOS programming:
    : [code]
    : main:
    :
    : ...
    :
    : END main
    : [/code]
    : Maybe, in NASM it is different. Never tried NASM.
    :
    : Now, you do not need any .H files, from C/C++ programming, so no need for this WINUSER.H file, just maybe import that USER32.LIB.
    :
    : Again, no idea how it is done in NASM, but in FASM - you simply hook the functions you need with a very simple macro statement. Check it out - it is very easy! And in FASM - no need to link anything - you get your EXE file right there - from the ASM file![/blue]
    [/red]

    [green]
    Yea I know I was just using this as example code and it wasn't going to be used for any kind of program. :-)
    [/green]

Sign In or Register to comment.