X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Rod Pemberton" Newsgroups: comp.os.msdos.djgpp Subject: Re: gcc as a linker.... Date: Mon, 14 Jan 2008 06:58:02 -0500 Organization: Aioe.org NNTP Server Lines: 97 Message-ID: References: <478b3603$0$36444$4fafbaef AT reader5 DOT news DOT tin DOT it> NNTP-Posting-Host: IVw7K97ih4IohxRqyKkqFw.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse AT aioe DOT org X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-Priority: 3 X-MSMail-Priority: Normal To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "linus" wrote in message news:478b3603$0$36444$4fafbaef AT reader5 DOT news DOT tin DOT it... > I 've compiled with nasm the code below and linked with your gcc... > What does it mean these errors ? (the environment is Win XP ). > Sorry, I am a beginner...gcc can be used as a linker ? > Thanks a lot. > > C:\> gcc -oEXE hello.obj gcc -o hello.exe hello.obj I'm assuming that the code below is hello.asm and you've assembled with NASM like so: nasm -f coff -o hello.obj hello.asm > c:/djgpp/lib/crt0.o:crt0.s:(.data+0xc2): undefined reference to `_main' > c:/djgpp/lib/libc.a(crt1.o):crt1.c:(.text+0x404): undefined reference to > `_main' > > collect2: ld returned 1 exit status This is because there is no "_main" label in the code below. > SECTION .data ; data section > msg: db "Hello World",10 ; the string to print, 10=cr > len: equ $-msg ; "$" means "here" > ; len is a value, not an address > > SECTION .text ; code section > ; global main ; make label available to linker > ;main: ; standard gcc entry point > You've commented out the two lines (semi-colon at start of lines) that define 'main', but for assembly you want '_main' like so: global _main ; make label available to linker _main: ; standard gcc entry point > mov edx,len ; arg3, length of string to print > mov ecx,msg ; arg2, pointer to string > mov ebx,1 ; arg1, where to write, screen > mov eax,4 ; write sysout command to int 80 hex > int 0x80 ; interrupt 80 hex, call kernel > "int 0x80" is a Linux 32-bit function call. This won't work for DOS. I'll give a working example for DOS below. > mov ebx,0 ; exit code, 0=normal > mov eax,1 ; exit command to kernel > int 0x80 ; interrupt 80 hex, call kernel "int 0x80" is a Linux 32-bit function call. This won't work for DOS. I'll give a working example for DOS below. DOS is 16-bit, but DJGPP produces 32-bit DPMI executables for 16-bit DOS using a DPMI host. The 16-bit conversion of your program is easy and only requires NASM. A 32-bit DOS example which links using DJGPP's GCC requires a bit more work... Basically, your code - including the string - is above 1Mb, however, the string must be relocated below 1Mb using DOS and DPMI calls, before it can be printed. The proper method is much longer in assembly. I was hoping to find a shorter method. This would be useful to me, so I may get back to you on the 32-bit version. Or, I may not... ; nasm -f bin -o hello.com hello.asm BITS 16 ORG 0x100 SECTION .text ; code section push cs pop ds ; offset portion of pointer to string mov dx, msg ; segment portion of pointer to string mov ah,09h ; write string command to int 21 hex int 0x21 ; interrupt 21 hex, call DOS mov al,0 ; exit code, 0=normal mov ah,4ch ; exit command to kernel int 0x21 ; interrupt 21 hex, call DOS msg: db "Hello World",13,10,'$' ; the string to print, 10=cr, 13=lf, $=terminator Another option might be Mike Gonta's aeBIOS. You should be able to do a 32-bit version almost like the code above. http://groups.google.com/group/aeBIOS http://www.mikegonta.com/aeBIOS/ (2nd is a link to binaries - which was has been down for a few days...) Rod Pemberton