NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on August 05, 2009, 10:56:21 AM
-
I have this code:
section .text use32
global _main
extern _printf
_main:
; printf("Liczba jeden to: %d\n", 1);
push dword 1 ; drugi argument
push dword napis ; pierwszy argument
call _printf ; uruchomienie funkcji
add esp, 4 ; posprz?tanie stosu
add esp, 4 ; posprz?tanie stosu
; return 0;
xor eax, eax
ret ; wyj?cie z programu
section .data use32
napis: db "Liczba jeden to: %d", 10, 0
And I have a question.
Is here anyone who can compile and make it going ??
And if yes what did you use to build it ?
-
I will add that I use 32BIT windows
-
Hi -
I am not the moderator of this forum but I can give you some guidance. First, go to http://www.drpaulcarter.com (http://www.drpaulcarter.com) and download paul carter's nasm tutorial. Chapter 2 will give you the basic build stuff for a makefile.
You need to link to the C run-time libraries to do the call to printf. The easiest way to get started with this is to follow Carter's discussion of a "driver" written in C that will call your program, which in turn, will let you call printf or any other c function. You need the driver as a short cut to getting access to the c libraries. It's not elegant, but it will work for the moment.
A more elegant solution would be to call printf directly without using a c coded driver. A moderator such as Frank who has handled my beginner questions is the right person to discuss how to get to the c libraries without resorting to a driver. Obviously you will need some includes in your code (which you don't currently have in the sample you sent). Since the includes are going to almost certainly require accessing files outside your current directory you'll need code that sends the linker there.
That's maybe some help.
I'm glad you raised the question, because it is a part of the linking process that is not well handled in Paul Carter's very fine tutorial. I'll bet a lot of NASM beginners have exactly the same question.
Ciao
Mark Allyn
-
What this include instruction should include ?
is it a library or source code ?
And where can I get more info about includes ?
I heard also that I can use an address to invoke function.
is it true ?
and if it is how can I retrieve this addres ?