News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

C Standard Library Functions

Started by MusicalMike, November 10, 2005, 12:45:58 AM

Previous topic - Next topic

MusicalMike

I read in a book I am reading on assembly language programming that GAS allows you to use the c standard library functions by simply linking the standard c library files with your assembly program, though hutch has done a great job replicating a couple of string manipulation functions from the c standard library, I was wondering, if its posible to use the c standard library functions from an assembly app. I for instance would rather call printf once than, use the dwtoa funcgion and then the stdout function to display an integer value. If so, please tell me how, if not, tell hutch to fix it.

GregL

Yes, you can call C Run-Time Library functions from MASM32. Here ia a simple example:

.386
.model flat,stdcall
option casemap:none

include windows.inc

include kernel32.inc
include user32.inc
include msvcrt.inc

includelib kernel32.lib
includelib user32.lib
includelib msvcrt.lib

CR EQU 13
LF EQU 10

.DATA

    strHello BYTE "This is an example of using 'printf' from MASM32", LF, 0
    strFmt   BYTE "%s", 0

.CODE

start:

    invoke crt_printf, ADDR strFmt, ADDR strHello
    invoke ExitProcess, 0

end start


All the functions are prefixed with 'crt_' to avoid conflicts with masm32.lib and other libraries.



Vortex

Hi Mike,

Beside msvcrt.dll, you can use also the functions from the C run-time library crtdll.dll

hutch--

Mike,

> If so, please tell me how, if not, tell hutch to fix it.

Understand in this world I don't do requests on this basis. If you wish to use the C runtime library, learn to write the prototypes and use it, you can also use the MSVCRT C runtime functions as Greg mentioned. The MASM32 library is not related to either and is hand written assembler code complete with source. If you cannot find what you need out of this lot, you can always write your own.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MusicalMike

 :bdg Hutch, when you said you don't do requests, I got a mental picture of you in a suit and top hat, with a kane doing dance step routines with a bucket full of spair change. LOL. Joking asside, I know I said that if the feature wasn't supported that you should add it, but that is completely different from formally requesting that you do it. In any event, since the feature is supported, its a non issue anyway. I do however understand where you are comming from and will bare it in mind next time I make a post of this nature. Insidently, the above responses were right on target with respect to what I was seeking. One problem is, I looked through the files that came with the masm32 package, and msvcrt.lib/inc is not amoung them. Please help me locate those files. Thanks.

GregL


Vortex

Mike,

It's easy to create the import library with Pelle's librarian Polib :

polib /OUT:msvcrt.lib \windows\system32\msvcrt.dll
or
polib /OUT:msvcrt.lib \windows\system\msvcrt.dll
( depending on your operating system )

redskull

i know this kind of off topic, but I remember an h2inc.exe program that came with the old-school version of Masm, specifically to convert C-style header files to ASM-style header files.  I'm assuming it doesn't work with Windows.h, or else there wouldn't be a hand-written version of it with masm32, but would this program work with other C libraries?

alan
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Vortex

That h2inc tool outputs a lot of errors. Hutch and Iczelion worked to create the master include file windows.inc ( See the header of that file. )