From owner-freebsd-questions Wed Dec 1 11: 4: 0 1999 Delivered-To: freebsd-questions@freebsd.org Received: from ultra3000.if.sc.usp.br (uspfsc.ifqsc.sc.usp.br [143.107.228.1]) by hub.freebsd.org (Postfix) with ESMTP id ED95B15BDE for ; Wed, 1 Dec 1999 11:03:42 -0800 (PST) (envelope-from toto@ultra3000.if.sc.usp.br) Received: (from toto@localhost) by ultra3000.if.sc.usp.br (8.8.8/8.8.8) id RAA09268; Wed, 1 Dec 1999 17:02:45 -0200 (EDT) Date: Wed, 1 Dec 1999 17:02:45 -0200 (EDT) From: Carlos Antonio Ruggiero Message-Id: <199912011902.RAA09268@ultra3000.if.sc.usp.br> To: freebsd-questions@freebsd.org, sarig@bezeqint.net Subject: Re: Hello World in Assembler Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> I am trying to write a "hello world" program in assembler, but can't get >> it right. The code is (based on The Assembly HOW-TO) >> >> section .data >> >> msg db "Hello World!" >> len equ $ - msg >> >> section .text >> >> global _start >> >> _start: >> >> mov eax,4 >> mov ebx,1 >> mov ecx,msg >> mov edx,len >> int 0x80 >> >> mov eax,1 >> xor ebx,ebx >> int 0x80 >Ahem, wouldn't this be simpler? > >section .data >msg db "Hello, World!" >section .text >global _start >_start: >push word msg >call printf > >and build with: >nasm -f elf -o hello.o hello.asm >ld -lc -o hello hello.o > > (I didn't try this, but I think it should work) >-- >Oren Sarig >sarig@bezeqint.net You see, this is the point! I want to use freebsd for assembly language classes and would like to avoid C as much as possible. You are right that a code like yours should work. This one is fine: section .data msg db "Hello World",0x0A len equ $ - msg section .text extern write global main main: push ebp mov ebp,esp push long len push long msg push long 1 call write add esp, 12 leave ret And if you compile and run... toto@atm3:ttyp1 ~/cursos (156)> nasm -f elf -o hello.o hello.asm toto@atm3:ttyp1 ~/cursos (157)> gcc -v -o hello hello.o gcc version 2.7.2.1 /usr/libexec/elf/ld -m elf_i386 -dynamic-linker /usr/libexec/ld-elf.so.1 -o hello /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/libdata/gcc hello.o /usr/lib/libgcc.a -lc /usr/lib/libgcc.a /usr/lib/crtend.o /usr/lib/crtn.o toto@atm3:ttyp1 ~/cursos (158)> ./hello Hello World toto@atm3:ttyp1 ~/cursos (159)> However, the link command is quite something! There is too much of extra code like crt1.o, crti.o crtbegin.o libgcc, etc which I would like to avoid. Students tend to think this is "cheating"! They will say: "this code is easier" main() { write(1,"Hello World\n",12); } Any other suggestions? Toto toto@ifsc.sc.usp.br To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message