From: Rod Pemberton on

"Evenbit" <nbaker2328(a)charter.net> wrote in message
news:52f209d8-14c0-4bb6-86f0-> For instance,
> a recent question at win32-nasm list asked how to make calls to the
> Visual C standard library...

The Mammon's link has all the calling conventions: stdcall, fastcall, cdecl
(as ccall ), and pascal (as pcall) as well as standard C flow control:
if-then-else, switch, case, default, break, do-while, procedure setup,
variable and data allocation and storage - plus something called do-for.
I'm not sure if the calling conventions are compatible with the MASM 5.1
definitions of calling conventions. MASM 5.1 says stdcall selects between
the variatic argument cdecl and the fixed argument pascal calling
conventions. That doesn't seem to be Mammon's stdcall does, although it
does say it's for Windows. Some of that functionality was duplicated in the
other links by other authors. You might also look at the two other sources
Frank mentioned.


Rod Pemberton

From: Evenbit on
On Nov 30, 10:14 am, "Rod Pemberton" <do_not_h...(a)nohavenot.cmm>
wrote:
> "Evenbit" <nbaker2...(a)charter.net> wrote in message
>
> news:52f209d8-14c0-4bb6-86f0-> For instance,
>
> > a recent question at win32-nasm list asked how to make calls to the
> > Visual C standard library...
>
> The Mammon's link has all the calling conventions: stdcall, fastcall, cdecl
> (as ccall ), and pascal (as pcall) as well as standard C flow control:
> if-then-else, switch, case, default, break, do-while, procedure setup,
> variable and data allocation and storage - plus something called do-for.
> I'm not sure if the calling conventions are compatible with the MASM 5.1
> definitions of calling conventions. MASM 5.1 says stdcall selects between
> the variatic argument cdecl and the fixed argument pascal calling
> conventions. That doesn't seem to be Mammon's stdcall does, although it
> does say it's for Windows. Some of that functionality was duplicated in the
> other links by other authors. You might also look at the two other sources
> Frank mentioned.
>

I see that Frank has been sharing his "holiday smoke" with you. :)
People who are new to Nasm often need more information than what a
"Mammon macro" can provide. For instance, the macro doesn't mention
anything about linker switches. You can see from the two "answer
posts" (pasted below) that they provided a more complete picture.

Nathan.

-----------------------------------------------------
{from Tony Apicella}

Re: calling printf?

Compile with this: C:\Nasmx\Bin\NASM -fwin32 "printf.asm"

Link with this: C:\Nasmx\Bin\GoLink /console /entry _main printf.obj
kernel32.dll user32.dll msvcrt.dll

%include '..\..\..\..\nasmx\inc\nasmx.inc'
%include '..\..\..\..\nasmx\inc\win32\msvcrt.inc'

section .data ; preset constants, writeable
fmtInt: db "value = %d",10,0 ; format string for printf
fmtFlt: db "value = %f",10,0 ; format string for printf
a: dq 0.0;
section .text
global _main
_main:
;
; Example of call printf for an integer
;
mov eax,97462 ; print this integer
push eax
push fmtInt
call printf
add esp, 8 ; put the stack back where it was
;
; Example of call printf for a float
;
fldpi ; put PI on the floating point stack.
fst qword [a] ; print this floating value
push dword [a+4] ; double a (bottom)
push dword [a] ; double a
push dword fmtFlt;
call printf
add esp, 12 ; put the stack back
;
; Example of invoke printf
;
invoke printf, "%c%c%c%cPress any key to exit.",13,10,13,10
invoke _getch
mov eax,0 ; exit code, 0=normal
ret ; main returns to operating system

---------------------------------------------------------------
{from numit_or}

Re: [win32-nasm-users] calling printf?

El Friday 02 November 2007 18:40:49 mugg escribió:

> How do I make calls to MSVC runtime functions like printf instead of
> the standard way of making calls to simple win32 api like
> "WriteConsoleA"?


If you use ld from windows (cygwin or mingw) and you want to call
functions
like printf, you have to prefix a "_" to the function name that you
are
calling.

The functions like printf are called following the C calling
convention, so
you must clean up the stack removing all the pushed arguments.

; -- hell.asm

section .text
global entry
extern _printf

entry:
push dword hell ; push the adress of the string (4 bytes)
call _printf
add esp, 4 ; clean the 4 bytes pushed above
ret

hell db "hello", 0Ah, 0

; ----

To compile it (from msys or mingw):

nasm hell.asm -o hell.obj -fwin32
ld hell.obj -o hell.exe -e entry --subsytem console -lmsvcrt

-------
nmt
From: Phil Carmody on
"Wolfgang Kern" <nowhere(a)never.at> writes:
> Evenbit wrote:
>
> [...]
>
> > Asmers have an excellent excuse -- just blame it all on this Phil
> > feller... he "gets around" to more CPUs than just this x86 sweety...
> > kind of a "metro-"... and his Mrs. Piggy pink background...
> >
> > http://fatphil.org/x86/index.html
> >
> > ... makes everyone feel all oinky! :-)
>
> Now it's obvious, Mrs.Piggy need more than just one wonder-bra :)
> but there are some useful things on Phil's page, even a bit dated ...

Yeah, I'm acting like archive.org when it comes to that.

I'm in a bit of a moral dilemma actually. Several years ago,
I was given permission by Agner to put the split document
up on my website as long as I added his attribution to every
page, and a link back to his original, which I gladly did.
However, he recently dropped me a mail asking me to remove
them. I think it would be a shame to do so, as they are
still quite popular, looking at my logs.

As I say, I'm in a bit of a quandry.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration
First  |  Prev  | 
Pages: 1 2
Prev: Mammon's NASM macro's
Next: Sudoku