ورود

View Full Version : مبتدی: مشکل در اجرای کد در MASM32



Collector
شنبه 28 اردیبهشت 1392, 14:50 عصر
سلام
من میخوام این کد که فیبوناچی را محاسبه میکنه را در MASM 32 کامپایل کنم
اما از سگمنت ها خطا میگیره ممکنه راهنمایی بفرمایید


ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000


section .bss
F resq 20 ; reserve 20*8 bytes
section .text
global _start
_start:
call Fib
Fib:
mov cx, 20 ; number of sequence elements
mov esi, F ; esi points to the begining of array F
mov rax, 0 ; rax contains the current number
mov rbx, 1 ; rbx points to the previous number
do:
mov rdx, rax ; store current number in rdx
add rax, rbx ; generate next number and store it in rax
mov rbx, rdx ; move current number to rbx
; the above 3 instructions can be replaced by 'xadd rax, rbx'
mov [esi], rax ; store the generated number in memory
add esi, 8 ; points to the next memory position
loop do ; repeat these process
end:
ret.

Collector
شنبه 28 اردیبهشت 1392, 18:03 عصر
این کد با NASM نوشته شده
من ورژن تحت ویندوز که از اینجا (http://sourceforge.net/projects/nasm/) قابل دانلود هست را دانلود کردم.

الان توی کد زیر چطوری میشه بودن استفاده از توابع C و با استفاده از توابع خود کامپایل خروجی را مشاهده کرد.
من الان کامپایلش کردم اما از اون تابع Printf خطا میگیره


C:\>nasm -f win32 test.asm -o test.o

C:\>ld test.o -o test.exe


ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
2.o(.text+0x6):2.asm: undefined reference to `printf'



; ----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It needs to be linked with a C library.
; ----------------------------------------------------------------------------

global _main
extern _printf

section .text
_main:
push message
call _printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0