I am trying to compile this program under NASM (x86-64, Windows).
; prime.asm
global _main
extern _scanf
extern _printf
section .data:
n: dd 0
i: dd 2
format_string_scanf: db '%d', 0x0A
format_string_no_printf: db 'The number %d is not prime', 0x0A
format_string_yes_printf: db 'The number %d is prime', 0x0A
section .text
_main:
push n
push format_string_scanf
call _scanf
cmp dword [n], 1
je NOT_PRIME
cmp dword [n], 0
je NOT_PRIME
FOR_LOOP:
mov eax, [i]
mul dword [i]
cmp eax, [n]
jg IS_PRIME
mov edx, 0
mov eax, [n]
div dword [i]
cmp edx, 0
je NOT_PRIME
jmp FOR_LOOP
IS_PRIME:
push qword [n]
push format_string_yes_printf
call _printf
jmp PROGRAM_END
NOT_PRIME:
push qword [n]
push format_string_no_printf
call _printf
PROGRAM_END:
ret
These are the options I use:
nasm.exe -f win64 -o prime.obj prime.asm
link.exe prime.obj /subsystem:console /entry:_main
NASM does fine, however link.exe
throws 2 errors:
prime.obj : error LNK2001: unresolved external symbol _scanf
prime.obj : error LNK2001: unresolved external symbol _printf
prime.obj : fatal error LNK1120: 2 unresolved externals
I guess it is failing to link to the C Runtime one way or another. Can somebody help me out to solve these 2 errors?