NASM with GCC or Visual C++
Posted: Sat May 19, 2012 8:46 am
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
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