NASM with GCC or Visual C++

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
golfexodus
Posts: 2
Joined: Fri May 18, 2012 2:06 pm

NASM with GCC or Visual C++

Post 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
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: NASM with GCC or Visual C++

Post 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.
Attachments
Безымянный.PNG
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: NASM with GCC or Visual C++

Post by gedd »

What you are doing is not clear.
Please take a while to give some details.
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
LindusSystem
Member
Member
Posts: 63
Joined: Sat Apr 28, 2012 9:41 am
Location: Earth -> Asia

Re: NASM with GCC or Visual C++

Post 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
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: NASM with GCC or Visual C++

Post 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).
Post Reply