we have already known that there should be some initialization to
work with the stl. To use that library. There are objects that there
should be initialized before entering main.

I think that I receive this run time SIGSEG due to that.
So any idea ?

I have use a simple C++ program and compiled it only and make the
printf.o.using this command

#include <iostream>

extern "C"
{
 
void print ( int a )
{
     std::cout << a << std::endl;
}
     
          
}
g++ -c printf.o

and this is the nasm print.asm

extern _printf 


SECTION .data

a	dd 	5 ; int a = 5;

SECTION .text ; code section
global main
global _WinMain@16
main:
	push ebp
	mov  ebp ,esp 
	mov  eax , [a]
	push eax 
	call _printf 
	pop ebp
	ret
_WinMain@16:
	mov eax , 0
        call main
	ret 16
nasm -f elf print.asm
g++ -g -o print.exe print.o printf.o

and when I run this , it gives an SIGSEGV inside the function ,

(gdb) step
Single stepping until exit from funct
which has no line number information.
0x7c90eaf0 in _libmsvcrt_a_iname ()

_libmsvcrt_a_iname () << method $ucks !, C stdlib printf works fine ,but for this probablly this is due
to non initialized standard library global static objects.

how can I do this when I write the _WinMain@16 method method
inside the asm file ? How can I say or call a method to initialize
the stl ?

what to do in this situation.
I need you're expertise.

--thanks in advance--

You don't seem to call print. Your code only calls printf (see line 16 of a nasm code), passing argument as it to print. Of course printf gets confused and segfaults.

PS: You have a debugger. Why didn't you use it?

b main
run
si
si
si
si
si

and find yourself in printf.

You don't seem to call print. Your code only calls printf (see line 16 of a nasm code), passing argument as it to print. Of course printf gets confused and segfaults.

ya ! a simple spelling mistake. It works fine now.

sorry I'm a nasm newbie. However I completely managed to run it.

I put the correct version of this code for a person who dig this thread
in future. For completeness.

extern _print


SECTION .data

a	dd 	5 ; int a = 5;

SECTION .text ; code section
global main
global _WinMain@16
main:
	push ebp
	mov  ebp ,esp 
	mov  eax , [a]
	push eax 
	call _print 
	mov  esp, ebp
	pop  ebp
	ret
_WinMain@16:
	mov eax , 0
        call main
	ret 16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.