तक पहुंचने के लिए NASM बाहरी कथन का उपयोग करते समय मैं NASM सीख रहा हूं और इस कोड को संकलित करने के लिए टाइप कर रहा हूं (जिसे मैंने here पाया)।जीसीसी आउटपुट "प्रिंटफ 'के लिए अनिश्चित संदर्भ" प्रिंटफ
nasm -f coff -l printf.lst printf1.asm
printf.o
करने के लिए
लेकिन इस जीसीसी जोड़ने आदेश:
gcc -o printf1 printf1.o
त्रुटि के साथ विफल:
printf1.o:printf1.asm:(.text+0x1a): undefined reference to `printf'
collect2: ld returned 1 exit status
क्या मैं गलत कर रहा हूँ यह इस एनएएसएम आदेश का उपयोग असेंबल? अग्रिम में धन्यवाद। (संपादित करें: मैं विंडोज 7 पर हूं);
; printf1.asm print an integer from storage and from a register
; Assemble: nasm -f coff -l printf.lst printf1.asm
; Link: gcc -o printf1 printf1.o
; Run: printf1
; Output: a=5, eax=7
; Equivalent C code
; /* printf1.c print an int and an expression */
; #include
; int main()
; {
; int a=5;
; printf("a=%d, eax=%d\n", a, a+2);
; return 0;
; }
; Declare some external functions
;
extern printf ; the C function, to be called
section .data ; Data section, initialized variables
a: dd 5 ; int a=5;
fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'
section .text ; Code section.
global _main ; the standard gcc entry point
_main: ; the program label for the entry point
push ebp ; set up stack frame
mov ebp,esp
mov eax, [a] ; put a from store into register
add eax, 2 ; a+2
push eax ; value of a+2
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; Call C function
add esp, 12 ; pop stack 3 push times 4 bytes
mov esp, ebp ; takedown stack frame
pop ebp ; same as "leave" op
mov eax,0 ; normal, no error, return value
ret ; return
यह अब संकलित करता है लेकिन जब मैं "printf1.exe" खोलता हूं तो यह दुर्घटनाग्रस्त हो जाता है। क्या वे चल रहे हैं, जबकि NASM किए गए प्रोग्राम डीबग करने का कोई तरीका है? –
बस इसे WinDBG या इसी तरह खोलें। –
मेरे सभी जीसीसी जुड़े NASM प्रोग्राम विफल हो रहे हैं :(मुझे आश्चर्य है कि क्यों? –