Page 1 of 1

NASM with GCC or Visual C++

Posted: Sat May 19, 2012 8:46 am
by golfexodus
I'm new to OS development, how do i compile and execute nasm using gcc. Whenever i try to compile nasm using visual C++ I always get - LINK : fatal error LNK1561: entry point must be defined.

This is my source code:

%include "asm_io.inc"

segment .data

prompt1 db "Enter first number: ", 0
prompt2 db "Enter second number: ", 0
outmsg1 db "You entered ", 0
outmsg2 db "and ", 0
outmsg3 db "The sum is ", 0

segment .bss

input1 resd 1
input2 resd 1

segment .text

global _asm_main
_asm_main:
enter 0,0 ; set up routine
pusha

mov eax, prompt1 ; print out prompt
call print_string

call read_int ;read integer
mov [input1], eax ;store into input1

mov eax, prompt2 ; print out prompt
call print_string

call read_int ;read integer
mov [input2], eax ;store into input2

mov eax, [input1] ;eax = dword at input1
add eax, [input2] ;eax += dword at input2

mov ebx, eax ;ebx = eax

dump_regs 1 ;print out register values
dump_mem 2, outmsg1, 1 ;print out memory

;print out result messages as series of step

mov eax, outmsg1
call print_string
mov eax, [input1]
call print_int
mov eax, outmsg2
call print_int
mov eax, outmsg3
call print_string
mov eax, ebx
call print_int ;print sum(ebx)
call print_nl ;print new line

popa
mov eax, 0 ;return to C
leave
ret

Re: NASM with GCC or Visual C++

Posted: Sat May 19, 2012 9:45 am
by Nable
I don't get how exactly you are trying to compile it, what cmdline do you use?

Also, if you are using MSVS projects, then you must specify entry point for you application.

Re: NASM with GCC or Visual C++

Posted: Mon May 21, 2012 8:27 am
by gedd
What you are doing is not clear.
Please take a while to give some details.

Re: NASM with GCC or Visual C++

Posted: Mon May 21, 2012 9:12 am
by LindusSystem
You may use GNU C Compiler and NASM.
And use the extern keyword to tell the compiler/assembler that it is defined elsewhere in other language and define a variable/function in assembly as global if you want to call it in C with extern.

Build Process:
Assemble
Compile
Link

Advantages of using GCC:
1]You can compile your C Scripts in Linux,Windows(AS GCC is available for both platforms),etc too whereas VC Scripts compile only on Windows(AS VC Compiler is for Windows)

2]Cross-Compiler

3]VC++ Errors are sometimes rubbish

If you have no idea of linking,assembling,etc ,try the Brans Kernel Tutorial there you will get to know to linker script and how to build scripts

Re: NASM with GCC or Visual C++

Posted: Mon May 21, 2012 4:00 pm
by Casm
If you are linking from the command line with Microsoft's linker, use the switch /ENTRY:main. Replace "main" with whatever your entry point is (and remember to make it "public" in the asm source file).