954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I'm a beginner. How do I call main in assembler?

If there are multiple ways to do this, would you name a few, please?

Giering
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

what does the assembler do is just convert the assembly language
source file into a object file. file name ended with .a .obj .o like extension.

I'm using nasm and suggest you too use it.With this command like you
assembling it to a object file.

nasm -f elf HelloWorld.asm


and you need a linker , I have mingw installed in my windows machine
so I suggested to use mingw ld linker to link this.But you need extra
libraries to pass to use the functions like _printf , so that we use the
gcc ( GNU C compiler's fontend for 'ld') , but actually 'ld' is using.

J:\EXERCISES\Assembly\hello>
J:\EXERCISES\Assembly\hello>nasm -f elf  HelloWorld.asm

J:\EXERCISES\Assembly\hello>gcc HelloWorld.o -o HelloWorld.exe -e _main

J:\EXERCISES\Assembly\hello>HelloWorld
hello, World

J:\EXERCISES\Assembly\hello>


Compile it and see yourself,This is the code for HelloWorld.asm,

global _main
	extern _printf 
	
	section .text
_main: 
	push message
	call _printf 
	add  esp , 4
	ret
message:
	db 'hello, World',10,0


NOTE: when you using a symbol as an entry point that symbol should
be global, and also you can specify the entry point using -e option in the
ld linker.

I think other linkers also give you to explicitly specify the entry point
of your program.

Download nasm and install mingw and do it by yourself. Best regards.

NicAx64
Posting Pro
536 posts since Mar 2009
Reputation Points: 86
Solved Threads: 43
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: