"Hello World!" implemented in gnu assembler

"Hello World!" implemented in gnu assembler

Post by Warwick Allis » Wed, 31 Jul 1996 04:00:00




Quote:>I was wondering if someone would be kind enough to write a simple
>gnu assembler program to greatly benefit my embark into the  world of
>assembly level programming. To preserve the rich programming tradition
>that our forefathers of unix have given us, I would like ...

   The Forefathers gave you C.

--
Warwick
--

/     * <- Comp Sci Department, McD: http://student.uq.edu.au/~s002434/mcl.html
\_.-._/    Univ. of Queensland, POV: http://student.uq.edu.au/~s002434/pov.html
     v     Brisbane, Australia. ME:  http://student.uq.edu.au/~s002434

 
 
 

"Hello World!" implemented in gnu assembler

Post by Warwick Allis » Wed, 31 Jul 1996 04:00:00




>>   The Forefathers gave you C.
>Naw, that was the young whipper-snappers...... real men write in machine code,
>and dubug with a core dump !   :--)

When I moved house recently, I found an old shorthand notebook with 6502
assembly code written on the left side and the hand-assembled machine-code
translation written on the right side.  I'm glad those days are gone.  The
only bit of 80x86 assembler I've done is hacking the early XFree86 binary
to apply a patch (I wasn't going to download the whole source, just to change
one byte!) to get my #9GXE64 card to work.

BTW, we still debug with core dumps, even if the default slackware config
disables them to protect the poor dimwit users from filling up their disk
space.

Why am I still spinning *on this thread?  Because I hate to see people
wasting their time with hand-written assembler.  The poster who mentioned
the -S option of GCC indicates the only good use for assembler.  Using this,
you can taylor crucial parts of your C code to compile efficiently into
assembler on some particular hardware platform, while still allowing it
to be portable (if perhaps not so efficiently) to other platforms.

--
Warwick
--

/     * <- Comp Sci Department, McD: http://www.veryComputer.com/~s002434/mcl.html
\_.-._/    Univ. of Queensland, POV: http://www.veryComputer.com/~s002434/pov.html
     v     Brisbane, Australia. ME:  http://www.veryComputer.com/~s002434

 
 
 

"Hello World!" implemented in gnu assembler

Post by Geert Uytterhoev » Wed, 31 Jul 1996 04:00:00



|>
|> >I was wondering if someone would be kind enough to write a simple
|> >gnu assembler program to greatly benefit my embark into the  world of
|> >assembly level programming. To preserve the rich programming tradition
|> >that our forefathers of unix have given us, I would like ...
|>
|>    The Forefathers gave you C.

But they started with PDP-11 assembler :-)

Greetings,

                                                Geert

--

Wavelets, Linux/m68k on Amiga          http://www.cs.kuleuven.ac.be/~geert/
Department of Computer Science -- Katholieke Universiteit Leuven -- Belgium

 
 
 

"Hello World!" implemented in gnu assembler

Post by Jeffrey Russell Horn » Wed, 31 Jul 1996 04:00:00


Hello all,

I was wondering if someone would be kind enough to write a simple
gnu assembler program to greatly benefit my embark into the  world of
assembly level programming. To preserve the rich programming tradition
that our forefathers of unix have given us, I would like a simple source
file to implement the "Hello World!" program and the `as' and `ld'
commands to build the object file and create the executable.

  I've also put the various x86 asm faqs on my reading list, downloaded the
'interrupt list', and read the gnu assembler info files twice. But I'm still
a bit muddy.

BTW- I'm running Linux 1.2.13 with stock as (version 2.6), gcc (version 2.7.2),
and ld(version 2.6).

Thanks a WHOLE bunch,

jrh

--

Backups, Department of Computer Science
University of Tennessee, Knoxville

 
 
 

"Hello World!" implemented in gnu assembler

Post by Steven J. Linde » Wed, 31 Jul 1996 04:00:00



: >I was wondering if someone would be kind enough to write a simple
: >gnu assembler program to greatly benefit my embark into the  world of
: >assembly level programming. To preserve the rich programming tradition
: >that our forefathers of unix have given us, I would like ...

:    The Forefathers gave you C.

They also gave use the -S option to write assembly the easy way
cat >hello.c
#include <stdio.h>
int main()
{ printf("Hello World");
return 0;

Quote:}

^D
cc -S hello.c
  Assembly is now in hello.s

--

 
 
 

"Hello World!" implemented in gnu assembler

Post by Leonard Wojc » Wed, 31 Jul 1996 04:00:00


I

Quote:>>I was wondering if someone would be kind enough to write a simple
>>gnu assembler program to greatly benefit my embark into the  world of
>>assembly level programming. To preserve the rich programming tradition
>>that our forefathers of unix have given us, I would like ...
>   The Forefathers gave you C.

Naw, that was the young whipper-snappers...... real men write in machine code,
and dubug with a core dump !   :--)
 
 
 

"Hello World!" implemented in gnu assembler

Post by Jeffrey Russell Horn » Wed, 31 Jul 1996 04:00:00


Hello all,

I was wondering if someone would be kind enough to write a simple
gnu assembler program to greatly benefit my embark into the  world of
assembly level programming. To preserve the rich programming tradition
that our forefathers of unix have given us, I would like a simple source
file to implement the "Hello World!" program and the `as' and `ld'
commands to build the object file and create the executable.

  I've also put the various x86 asm faqs on my reading list, downloaded the
'interrupt list', and read the gnu assembler info files twice. But I'm still
a bit muddy.

BTW- I'm running Linux 1.2.13 with stock as (version 2.6), gcc (version 2.7.2),
and ld(version 2.6).

Thanks a WHOLE bunch,

jrh

--

Backups, Department of Computer Science
University of Tennessee, Knoxville

 
 
 

"Hello World!" implemented in gnu assembler

Post by Michael Meissn » Wed, 31 Jul 1996 04:00:00



| But they started with PDP-11 assembler :-)

Uhh, close but no cigar.  Try PDP-7 assembler :-)  The PDP-11 was the second
machine (and the first to use C for the kernel).
--
Michael Meissner, Cygnus Support (East Coast)
955 Massachusetts Avenue, Cambridge, MA 02138, USA

 
 
 

"Hello World!" implemented in gnu assembler

Post by Brian L. Naylo » Wed, 31 Jul 1996 04:00:00



> Hello all,

> I was wondering if someone would be kind enough to write a simple
> gnu assembler program to greatly benefit my embark into the  world of
> assembly level programming.

  I'm sorry that you haven't gotten a straight answer in any of these
public replies; I hope someone has emailed a suitable example to you.
I'm somewhat familiar with x86 assembler, though I have no experience
with gnu as.  I've heard it's quite different, so I probably won't
contribute myself.
  Like these others, I do prefer C to assembler (and very much so)
though I do acknowledge the speed and occasional suitability
of assembler after sitting through courses devoted to it.
  If you don't receive any helpful replies, feel free to email me for
example code tailored to DOS standards.  It might help some.

--
Brian L. Naylor

http://www.transy.edu/~jones

 
 
 

"Hello World!" implemented in gnu assembler

Post by Kevin Bu » Wed, 31 Jul 1996 04:00:00


-----BEGIN PGP SIGNED MESSAGE-----


|
| I was wondering if someone would be kind enough to write a simple
| gnu assembler program to greatly benefit my embark into the  world of
| assembly level programming.

The attached, compiled with:

        gcc -o hello hello.S

should work fine.  It illustrates how to perform a simple system call
(i.e., the "write" call) and the basic structure of a working assembly
program.

The best way to learn how to set up the structure of more complicated
programs (like programs that actually use writable memory variables),
is to use:

        gcc -S xxx.c

and examine the assembler output produced in "xxx.s".

Also, note the following two gotchas:

(a) the syntax of GNU x86 opcodes is different from most DOS
assemblers:

        mov eax, 1              ; the DOS way

        movl $1, %eax           /* the GNU way */

(b) any interrupt lists and "internals" documentation that you have
for DOS will be useless for writing assembly programs for Linux: the
environment in which a Linux program finds itself is completely
different from what a DOS program sees.

Frankly, you'll generally find it much more worthwhile to program only
the *occassional* function in assembly language and interface to it
from C code.  (In fact, since this "hello world" program uses the C
startup code anyway, it could be argued that this is really a C
program whose "main" function just happens to be written in
assembler.)

Good luck!


                        *       *       *

- ---BEGIN---
#include <linux/linkage.h>
#define __NR_write              4

.section        .rodata

hello:
        .string "Hello, world!\n"

.text

ENTRY(main)
        movl $hello,%edi
        movl %edi,%ecx          /* ecx == hello, the start of the string */
        xorb %al,%al
        pushl %ecx
        movl $0x100,%ecx
        repnz                   /* find length of string to max of 0x100 */
        scasb
        popl %ecx
        movl %edi,%edx
        subl %ecx,%edx
        decl %edx               /* edx == strlen(hello) */
        movl $1,%ebx            /* ebx == 1, stdout file handle */
        movl $__NR_write,%eax   /* eax == 4, number for "write" call */
        int $0x80               /* sys_write(ebx, ecx, edx)
        neg %eax
        jns leave               /* if error, return code */
        xorl %eax,%eax          /* otherwise, return 0 */
leave:
        ret
- ---END---

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
Comment: Processed by Mailcrypt 3.4beta, an Emacs/PGP interface

iQBVAwUBMf5ZgImVIQW1OgXhAQHYaAH/atKIIQLhgz0aFc6YYOYHiPx9v1iOsKN5
A8I8urAOi31030iz48TqT9UWBnfzj01nXxn2DuXW8A8mSuKgVz6wgQ==
=S5OK
-----END PGP SIGNATURE-----

 
 
 

"Hello World!" implemented in gnu assembler

Post by Lars Brinkho » Wed, 31 Jul 1996 04:00:00


Quote:>But they started with PDP-11 assembler :-)

Wasn't it PDP-7?
 
 
 

"Hello World!" implemented in gnu assembler

Post by Kobalt of No » Thu, 01 Aug 1996 04:00:00


Hello:

Quote:> >I was wondering if someone would be kind enough to write a simple
> >gnu assembler program to greatly benefit my embark into the  world of
> >assembly level programming. To preserve the rich programming tradition
> >that our forefathers of unix have given us, I would like ...

>    The Forefathers gave you C.

Hey, but I've found very little info about gas and its nmemonics...

Kobalt likes a lot assembler.

Kobalt.
--

 
 
 

"Hello World!" implemented in gnu assembler

Post by Michiel Bola » Thu, 01 Aug 1996 04:00:00




>> Hello all,

>> I was wondering if someone would be kind enough to write a simple
>> gnu assembler program to greatly benefit my embark into the  world of
>> assembly level programming.
>  I'm sorry that you haven't gotten a straight answer in any of these
>public replies; I hope someone has emailed a suitable example to you.

here's one

--

.globl _start
_start:
        movl $4,%eax            ! slot number of write() system call
        movl $1,%ebx            ! fileno(stdout)
        movl $hello,%ecx
        movl $13,%edx           ! strlen(hello)
        int $0x80
        movl $1,%eax            ! _exit()
        xorl %ebx,%ebx          ! exit with zero status
        int $0x80
hello:
        .string "hello, world\n"
--

University of Nijmegen
The Netherlands

 
 
 

"Hello World!" implemented in gnu assembler

Post by Scott Ear » Thu, 01 Aug 1996 04:00:00





>|>
>|> >I was wondering if someone would be kind enough to write a simple
>|> >gnu assembler program to greatly benefit my embark into the  world of
>|> >assembly level programming. To preserve the rich programming tradition
>|> >that our forefathers of unix have given us, I would like ...
>|>
>|>    The Forefathers gave you C.

>But they started with PDP-11 assembler :-)

I thought it started with BCPL, followed by 'B'?

        Scott

--
#include <disclaimer.h>

Scott Earle               || Amateur Callsigns : G0SWG, AA2WX



 
 
 

"Hello World!" implemented in gnu assembler

Post by Tony Co » Thu, 01 Aug 1996 04:00:00



:  A question - is there a DOS assember that takes the GNU syntax ?

gas from the DJGPP kit.

--


 
 
 

1. Final: "Hello World!" in implemented in gnu assembler

All,

Thanks for the replies to this newbie question, and especially those who
contacted my via email.

My conclusion: I certainly agree that it's more worthwhile to program in C
or another higher level language, but I'm striving for a  _deeper_
understanding, from boot time to halt, of how the kernel gets loaded into
memory and runs (and of course everything else)... and yes, the linux
kernel hacker's guide is on my reading list.

Again, thanks alot.

jrh

--

Backups, Department of Computer Science
University of Tennessee, Knoxville

2. log4cpp gives coredump

3. erroneous "hello" from forked "hello world" process!

4. java/43981: java/jdk1?-doc ports should dynamically generate plist file

5. "Hello World!" = "HellWrld" on Solaris 8, Linux ok

6. piping commands together/xargs/find??

7. how to tell if a mac is "new world " or "old world"

8. Good Networking Book?

9. "Hello,Hello,Hello-Whats going on here then?"

10. WWW: Third Issue of the "Brave GNU World", the monthly GNU forum

11. The monthly GNU forum "Brave GNU World" released sixth issue

12. First Issue of the "Brave GNU World", the monthly GNU column, is online now

13. GETSERVBYNAME()????????????????????"""""""""""""