How can I call C library functions from assembly language in MSVC 2008?

Microsoft Visual Studio Pro 2008 C ++ creates an excellent IDE for writing, building, and building pure assembler programs. Although I can create asm programs that bind to the Win32 API (for input and output of the console), I cannot bind to the C runtime library. Well, actually these links are good, but it gets the r6032 error at runtime - the library error is not initialized / loading incorrectly. Can someone tell me how to configure IDE (and code) to call C library functions? The following is an example call to printf. By the way, I used msvcrt.lib. I also tried libcmt.lib.

Thanks in advance.

        .586
        .model flat                             

        extern printf:near

        .data

msgTestClib db 'Greetings from library C.', 0

        .code

main PROC

        push    ebp

        mov ebp, esp

        push offset msgTestClib

        call printf

        add esp, 4

        pop ebp

        ret

main ENDP

        END
+3
1

, . . -, , VS 2005 , , , , VS. "". , , , .

:

;sh3.asm - test using c run-time library functions

.586
.model flat

EXTRN   _printf:PROC

        .data

msgHello DB ' C!', 0ah, 00h

.code

_main PROC

push OFFSET msgHello

call _printf

add esp, 4

ret 0

_main ENDP

END

, 1:

  • ; .asm . , _main. - .

  • MASM, ; Microsoft Macro Assembler.

  • → properties → linker → C. , msvcrt.lib msvcrtd.lib . : .

  • .

2:

  • ; .asm . . , .

  • MASM, ; Microsoft Macro Assembler.

  • → properties → linker → C. , msvcrt.lib msvcrtd.lib .

  • , Linker, , , , start.

  • , → : type = 'win32' name= 'Microsoft.VC90.CRT' version = '9.0.21022.8' processorArchitecture = 'x86' publicKeyToken = '1fc8b3b9a1e18e3b' .

  • .

, , , , , VS Windows. , 1, . , .

, 1 . _main - , C. . , : C, 2 ; !

, 1, API Win32 C, . , windows api, c .

, Windows Visual Studio. !

~ jiangshi

+4

All Articles