Assembly language is closer to what a computer understand and less like what a human would understand. but it is fast and compact. when assembled and linked vs a compiled higher level program. Assembly language version of Hello world:

section .data
	hello:     db 'Hello world!',10    ; 'Hello world!' plus a linefeed character
	helloLen:  equ $-hello             ; Length of the 'Hello world!' string
	                                   ; (I'll explain soon)
section .text
	global _start
_start:
	mov eax,4            ; The system call for write (sys_write)
	mov ebx,1            ; File descriptor 1 - standard output
	mov ecx,hello        ; Put the offset of hello in ecx
	mov edx,helloLen     ; helloLen is a constant, so we don't need to say
	                     ;  mov edx,[helloLen] to get it's actual value
	int 80h              ; Call the kernel
	mov eax,1            ; The system call for exit (sys_exit)
	mov ebx,0            ; Exit with return code of 0 (no error)
	int 80h

No real lesson here except to expose you to how it looks. To make it a program where the preceding code was saved as hw.asm, you would:

$ nasm -f elf hw.asm
$ ld -s -o hw hw.o
$ ./hw
Hello world!

The same program in the C language with out comments that would really make it a larger program of source code.

#include <stdio.h>
main()
{
          printf ("Hello world!\n");
}

Save file as “hello.c”. To make this program, you would:

$ gcc hello.c -o hw
$ ./hw
Hello world!

The hello.c file creates a program file of 8298 bytes. the hw.asm file creates a program file of 440 bytes. You can see that though the assembly program is a bit longer it generates a much smaller file. So assembly programs being all things are equal could save you up to ninety or more percent disk space. If you are renting storage, this could be a real money saver. Also the increase of speed in your system saves time and money also in other ways.

————————————————————————

Other examples of hello world:

Cobol (open-cobol using free form)

IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
PROCEDURE DIVISION.
 DISPLAY "Hello World!".
STOP RUN.

Basic (free basic)

print"Hello world!"
end

Pascal (free pascal)

program Hello_World;
Begin
                writeln('Hello World!')
End.

C++ (g++)

#include
using namespace std;
//hello.cpp
int main()
{
  cout &lt;&lt; &quot;Hello world!n&quot;;
  return 0;
}


Java (javac java)

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Python (interpreted)

print "Hello World!"
exit()

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print “Hello World!”
Hello World!
>>> exit()

Bash (interpreted)

$ printf "Hello world!n";
$ echo Hello world!

Fortran (gfortran (do not forget to start at column 6))

      program helloworld
         print *,"Hello World!"
      end program helloworld

Anyway, just some examples of “Hello world!” code to wet you appetite for programming. All the examples worked “as is” on linux with free software.

Note: For some reason the WordPress site messed up some of the code. so caveat emptor,

Advertisements