Transwiki:List of hello world programs
From Wikibooks, the open-content textbooks collection
The following is a list of Hello, world! programs.
Hello, world! programs make the text "Hello, world!" appear on a computer screen. It is usually the first program encountered when learning a programming language.
[edit] 4DOS batch
It should be noted that the 4DOS/4NT batch language is a superset of the MS-DOS batch language.
@echo Hello, world!
[edit] Ingres 4GL
message "Hello, world!" with style = popup;
[edit] ABAP - SAP AG
REPORT ZELLO. WRITE 'Hello, world!'.
[edit] ABC
WRITE "Hello, world!"
[edit] ActionScript
trace("Hello, world!");
[edit] ActionScript 3
package
{
import flash.display.Sprite;
public class HelloWorld extends Sprite
{
public function HelloWorld()
{
trace("Hello, world!");
}
}
}
[edit] Ada
with TEXT_IO; procedure HELLO is begin TEXT_IO.PUT_LINE ("Hello, world!"); end HELLO;
For explanation see Ada Programming:Basic.
[edit] ALGOL 68
In the popular upper-case stropping convention for bold words:
BEGIN
printf(($"Hello, world!"l$))
END
or using prime stropping suitable for punch cards on 6 bit character platforms:
'BEGIN'
PRINTF(($"HELLO, WORLD!"l$))
'END'
or minimally using the "brief symbol" form of begin and end.
( printf(($"Hello, world!"l$)) )
[edit] AmigaE
PROC main()
WriteF('Hello, world!');
ENDPROC
[edit] AMX NetLinx
This program sends the message out through the program port once during startup.
program_name = 'Hello' define_start send_string 0,'Hello World!'
[edit] APL
An explicit return function for the Hello, world! program may be coded as follows (note: TeX fonts are not correct)
- The Del on the first line begins function definition for the program named HWΔPGM. It is a niladic function (no parameters, as opposed to monadic or dyadic) and it will return an explicit result which allows other functions or APL primitives to use the returned value as input.
- The line labeled 1 assigns the text vector 'Hello, world!!' to the variable R
- The last line is another Del which ends the function definition.
When the function is executed but typing its name the APL interpreter assigns the text vector to the variable R, but since we have not used this value in another function, primitive, or assignment statement the interpreter returns it to the terminal, thus displaying the words on the next line below the function invocation.
The session would look like this
HWΔPGM
Hello, world!!
While not a program, if you simply supplied the text vector to the interpreter but did not assign it to a variable it would return it to the terminal as output. Note that user input is automatically indented 6 spaces by the interpreter while results are displayed at the beginning of a new line.
'Hello, world!'
Hello, world!!
[edit] AppleScript
See also GUI section.
return "Hello, world!"
[edit] ASCII
.-. .-. .-. .-. .-.
: : : : : : : : : :
: `-. .--. : : : : .--. .-..-..-. .--. .--. : : .-' :
: .. :' '_.': :_ : :_ ' .; : : `; `; :' .; :: ..': :_ ' .; :
:_;:_;`.__.'`.__;`.__;`.__.' `.__.__.'`.__.':_; `.__;`.__.'
[edit] ASP
<% Response.Write("Hello, world!") %>
- or simply:
<%= "Hello, world!" %>
[edit] ASP.NET
// in the page behind using C#
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Hello, world!");
}
// ASPX Page Template <asp:Literal ID="Literal1" runat="server" Text="Hello World!"></asp:Literal>
or
<asp:Label ID="Label1" runat="server" Text="Hello World"></asp:Label>
or
Hello World!
[edit] Assembly language
[edit] Accumulator-only architecture: DEC PDP-8, PAL-III assembler
See the example section of the PDP-8 article.
[edit] First successful uP/OS combinations: Intel 8080/Zilog Z80, CP/M, RMAC assembler
bdos equ 0005H ; BDOS entry point
start: mvi c,9 ; BDOS function: output string
lxi d,msg$ ; address of msg
call bdos
ret ; return to CCP
msg$: db 'Hello, world!$'
end start
[edit] Popular home computer: ZX Spectrum, Zilog Z80, HiSoft GENS assembler
10 ORG #8000 ; Start address of the routine 20 START LD A,2 ; set the output channel 30 CALL #1601 ; to channel 2 (main part of TV display) 40 LD HL,MSG ; Set HL register pair to address of the message 50 LOOP LD A,(HL) ; De-reference HL and store in A 60 CP 0 ; Null terminator? 70 RET Z ; If so, return 80 RST #10 ; Print the character in A 90 INC HL ; HL points at the next char to be printed 100 JR LOOP 110 MSG DEFM "Hello, world!" 120 DEFB 13 ; carriage return 130 DEFB 0 ; null terminator
[edit] Accumulator + index register machine: MOS Technology 6502, CBM KERNEL, MOS assembler syntax
A_CR = $0D ;carriage return
BSOUT = $FFD2 ;kernel ROM sub, write to current output device
;
LDX #$00 ;starting index in .X register
;
LOOP LDA MSG,X ;read message text
BEQ LOOPEND ;end of text
;
JSR BSOUT ;output char
INX
BNE LOOP ;repeat
;
LOOPEND RTS ;return from subroutine
;
MSG .BYT 'Hello, world!',A_CR,$00
[edit] Accumulator/Index microcoded machine: Data General Nova, RDOS
See the example section of the Nova article.
[edit] Expanded accumulator machine: Intel x86, DOS, TASM
MODEL SMALL
IDEAL
STACK 100H
DATASEG
MSG DB 'Hello, world!', 13, '$'
CODESEG
Start:
MOV AX, @data
MOV DS, AX
MOV DX, OFFSET MSG
MOV AH, 09H ; DOS: output ASCII$ string
INT 21H
MOV AX, 4C00H
INT 21H
END Start
[edit] ASSEMBLER x86 (DOS, MASM)
.MODEL Small .STACK 100h .DATA db msg 'Hello, world!$' .CODE start: mov ah, 09h lea dx, msg ; or mov dx, offset msg int 21h mov ax,4C00h int 21h end start
[edit] ASSEMBLER x86 (DOS, FASM)
; FASM example of writing 16-bit DOS .COM program ; Compile: "FASM HELLO.ASM HELLO.COM" org $100 use16 mov ah,9 mov dx,xhello int $21 ; DOS call: text output mov ah,$4C int $21 ; Return to DOS xhello db 'Hello world !!!$'
[edit] Expanded accumulator machine: Intel x86, Microsoft Windows, FASM
Example of making 32-bit PE program as raw code and data:
format PE GUI
entry start
section '.code' code readable executable
start:
push 0
push _caption
push _message
push 0
call [MessageBox]
push 0
call [ExitProcess]
section '.data' data readable writeable
_caption db 'Win32 assembly program',0
_message db 'Hello, world!',0
section '.idata' import data readable writeable
dd 0,0,0,RVA kernel_name,RVA kernel_table
dd 0,0,0,RVA user_name,RVA user_table
dd 0,0,0,0,0
kernel_table:
ExitProcess dd RVA _ExitProcess
dd 0
user_table:
MessageBox dd RVA _MessageBoxA
dd 0
kernel_name db 'KERNEL32.DLL',0
user_name db 'USER32.DLL',0
_ExitProcess dw 0
db 'ExitProcess',0
_MessageBoxA dw 0
db 'MessageBoxA',0
section '.reloc' fixups data readable discardable
[edit] Expanded accumulator machine: Intel x86, Linux, FASM
format ELF executable
entry _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
int 0x80
msg db 'Hello, world!', 0xA
msg_len = $-msg
[edit] Expanded accumulator machine:Intel x86, Linux, GAS
.data
msg:
.ascii "Hello, world!\n"
len = . - msg
.text
.global _start
_start:
movl $len,%edx
movl $msg,%ecx
movl $1,%ebx
movl $4,%eax
int $0x80
movl $0,%ebx
movl $1,%eax
int $0x80
[edit] Expanded accumulator machine: Intel x86, Linux, NASM
section .data
msg db 'Hello, world!',0xA
len equ $-msg
section .text
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov ebx,0
mov eax,1
int 0x80
[edit] Expanded accumulator machine: Intel x86, Linux, GLibC, NASM
extern printf ; Request symbol "printf". global main ; Declare symbol "main". section .data str: DB "Hello World!", 0x0A, 0x00 section .text main: PUSH str ; Push string pointer onto stack. CALL printf ; Call printf. POP eax ; Remove value from stack. MOV eax,0x0 ; \_Return value 0. RET ; /
[edit] General-purpose fictional computer: MIX, MIXAL
TERM EQU 19 console device no. (19 = typewriter)
ORIG 1000 start address
START OUT MSG(TERM) output data at address MSG
HLT halt execution
MSG ALF "HELLO"
ALF " WORL"
ALF "D "
END START end of program
[edit] General-purpose fictional computer: MMIX, MMIXAL
string BYTE "Hello, world!",#a,0 string to be printed (#a is newline and 0 terminates the string)
Main GETA $255,string get the address of the string in register 255
TRAP 0,Fputs,StdOut put the string pointed to by register 255 to file StdOut
TRAP 0,Halt,0 end process
[edit] General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11
.MCALL .REGDEF,.TTYOUT,.EXIT
.REGDEF
HELLO: MOV #MSG,R1
MOVB (R1)+,R0
LOOP: .TTYOUT
MOVB (R1)+,R0
BNE LOOP
.EXIT
MSG: .ASCIZ /Hello, world!/
.END HELLO
[edit] CISC Amiga (Workbench 2.0): Motorola 68000
include lvo/exec_lib.i
include lvo/dos_lib.i
; open DOS library
movea.l 4.w,a6
lea dosname(pc),a1
moveq #36,d0
jsr _LVOOpenLibrary(a6)
movea.l d0,a6
; actual print string
lea hellostr(pc),a0
move.l a0,d1
jsr _LVOPutStr(a6)
; close DOS library
movea.l a6,a1
movea.l 4.w,a6
jsr _LVOCloseLibrary(a6)
rts
dosname dc.b 'dos.library',0
hellostr dc.b 'Hello, world!',0
[edit] CISC Atari: Motorola 68000
;print
move.l #Hello,-(A7)
move.w #9,-(A7)
trap #1
addq.l #6,A7
;wait for key
move.w #1,-(A7)
trap #1
addq.l #2,A7
;exit
clr.w -(A7)
trap #1
Hello
dc.b 'Hello, world!',0
[edit] CISC on advanced multiprocessing OS: DEC VAX, VMS, MACRO-32
.title hello
.psect data, wrt, noexe
chan: .blkw 1
iosb: .blkq 1
term: .ascid "SYS$OUTPUT"
msg: .ascii "Hello, world!"
len = . - msg
.psect code, nowrt, exe
.entry hello, ^m<>
; Establish a channel for terminal I/O
$assign_s devnam=term, -
chan=chan
blbc r0, end
; Queue the I/O request
$qiow_s chan=chan, -
func=#io$_writevblk, -
iosb=iosb, -
p1=msg, -
p2=#len
; Check the status and the IOSB status
blbc r0, end
movzwl iosb, r0
; Return to operating system
end: ret
.end hello
[edit] Mainframe: IBM z/Architecture series using BAL
HELLO CSECT The name of this program is 'HELLO'
USING *,12 Tell assembler what register we are using
SAVE (14,12) Save registers
LR 12,15 Use Register 12 for this program
WTO 'Hello, world!' Write To Operator
RETURN (14,12) Return to calling party
END HELLO This is the end of the program
[edit] RISC processor: ARM, RISC OS, BBC BASIC's in-line assembler
.program
ADR R0,message
SWI "OS_Write0"
SWI "OS_Exit"
.message
DCS "Hello, world!"
DCB 0
ALIGN
or the even smaller version (from qUE);
SWI"OS_WriteS":EQUS"Hello, world!":EQUB0:ALIGN:MOVPC,R14
[edit] RISC processor: MIPS architecture
.data
msg: .asciiz "Hello, world!"
.align 2
.text
.globl main
main:
la $a0,msg
li $v0,4
syscall
jr $ra
[edit] RISC processor: PowerPC, Mac OS X, GAS
.data
msg:
.ascii "Hello, world!\n"
len = . - msg
.text
.globl _main
_main:
li r0, 4 ; write
li r3, 1 ; stdout
addis r4, 0, ha16(msg) ; high 16 bits of address
addi r4, r4, lo16(msg) ; low 16 bits of address
li r5, len ; length
sc
li r0, 1 ; exit
li r3, 0 ; exit status
sc
[edit] AutoHotkey
MsgBox, Hello`, world!
[edit] AutoIt
MsgBox(1,'','Hello, world!')
[edit] Avenue - Scripting language for ArcView GIS
MsgBox("Hello, world!","aTitle")
[edit] AWK
BEGIN { print "Hello, world!" }
[edit] B
This is the first known Hello, world! program ever written:[1]
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
[edit] Baan Tools
Also known as Triton Tools on older versions. On Baan ERP you can create a program on 3GL or 4GL mode.
Baan Tools on 3GL Format:
function main()
{
message("Hello, world!")
}
Baan Tools on 4GL Format:
choice.cont.process:
on.choice:
message("Hello, world!")
On this last case you should press the Continue button to show the message.
[edit] Bash or sh
See also UNIX-style shell.
echo "Hello, world!"
or
printf 'Hello, world!\n'
or using the C preprocessor
#!/bin/bash #define cpp # cpp $0 2> /dev/null | /bin/bash; exit $? #undef cpp #define HELLO_WORLD echo "hello, world" HELLO_WORLD | tr a-z A-Z
[edit] BASIC
[edit] General
The following example works for any ANSI/ISO-compliant BASIC implementation, as well as most implementations built into or distributed with microcomputers in the 1970s and 1980s (usually some variant of Microsoft BASIC):
10 PRINT "Hello, world!" 20 END
Note that the "END" statement is optional in many implementations of BASIC.
Some implementations could also execute instructions in an immediate mode when line numbers are omitted. The following examples work without requiring a RUN instruction.
PRINT "Hello, world!" ? "Hello, world!"
Later implementations of BASIC allowed greater support for structured programming and did not require line numbers for source code. The following example works when RUN for the vast majority of modern BASICs.
PRINT "Hello, world!" END
Again, the "END" statement is optional in many BASICs.
[edit] BlitzBasic
Print "Hello, world!" WaitKey
[edit] DarkBASIC
PRINT "Hello, world!" `or TEXT 0,0,"Hello, world!" WAIT KEY
Note: In the "classic" Dark Basic the WAIT KEY command is optional as the console goes up when the program has finished.
[edit] Liberty BASIC
To write to the main window:
print "hello"
Or drawn in a graphics window:
nomainwin open "Hello, world!" for graphics as #main print #main, "place 50 50" print #main, "\Hello, world!" print #main, "flush" wait
[edit] PBASIC
DEBUG "Hello, world!", CR
or, the typical microcontroller Hello, world! program equivalent with the only output device present being a light-emitting diode (LED) (in this case attached to the seventh output pin):
DO
HIGH 7 'Make the 7th pin go high (turn the LED on)
PAUSE 500 'Sleep for half a second
LOW 7 ' Make the 7th pin go low (turn the LED off)
PAUSE 500 'Sleep for half a second
LOOP
END
[edit] StarOffice/OpenOffice Basic
sub main
print "Hello, world!"
end sub
[edit] PureBasic
OpenConsole()
PrintN("Hello, world!")
Input()
or
MessageRequester("Hello, World","Hello, World")
or
Debug "Hello, World"
[edit] TI-BASIC
On TI calculators of the TI-80 through TI-86 range:
:Disp "Hello, world! (note the optional ending quotes) or :"Hello, world! (only works if on last line of program) or :Output(X,Y,"Hello, world! or :Text(X,Y,"Hello, world! (writes to the graph rather than home screen) or :Text(-1,X,Y,"Hello, world! (only on the 83+ and higher, provides larger text, home screen size)
Note: "!" character is not on the keypad. It can be accessed from "Catalog" or the "Probability" menu (as factorial notation).
On TI-89/TI-89 Titanium/TI-92(+)/Voyage 200 calculators:
:hellowld() :Prgm :Disp "Hello, world!" :EndPrgm
[edit] Visual Basic
Private Sub Form_Load() MsgBox "Hello, world" End Sub
Alternatively, copy this into a New Form:
Private Sub Form_Click() Form1.Hide Dim HelloWorld As New Form1 HelloWorld.Width = 2500: HelloWorld.Height = 1000: HelloWorld.Caption = "Hello, world!": HelloWorld.CurrentX = 500: HelloWorld.CurrentY = 75 HelloWorld.Show: HelloWorld.Font = "Tahoma": HelloWorld.FontBold = True: HelloWorld.FontSize = 12: HelloWorld.Print "Hello, world!" End Sub
[edit] Visual Basic .NET
Module HelloWorldApp
Sub Main()
System.Console.WriteLine("Hello, world!")
End Sub
End Module
or, defined differently,
Class HelloWorldApp
Shared Sub Main()
System.Console.WriteLine("Hello, world!")
End Sub
End Class
[edit] PICK/BASIC, DATA/BASIC, MV/BASIC
In addition to the ANSI syntax at the head of this article, most Pick operating system flavors of Dartmouth BASIC support extended syntax allowing cursor placement and other terminfo type functions for VDT's
X, Y positioning (colon ":" is the concatenation instruction):
PRINT @(34,12) : "Hello, world!"
Will display the string "Hello, world!" roughly centered in a 80X24 CRT.
Other functions:
PRINT @(-1) : @(34,12) : "Hello, world!"
Will clear the screen before displaying the string "Hello, world!" roughly centered in a 80X24 CRT.
Syntax variants:
CRT "Hello, world!"
Supporting the "@" functions above, the CRT statement ignores previous PRINTER statements and always sends output to the screen.
Some Pick operating system environments such as OpenQM support the DISPLAY variant of PRINT. This variant in addition to the "@" functions maintains pagination based upon the settings of the TERM variable:
DISPLAY "Hello, world!"
[edit] bc
"Hello, world!"
or, with the newline
print "Hello, world!\n"
[edit] BCPL
GET "LIBHDR"
LET START () BE
$(
WRITES ("Hello, world!*N")
$)
[edit] BLISS
%TITLE 'HELLO_WORLD'
MODULE HELLO_WORLD (IDENT='V1.0', MAIN=HELLO_WORLD,
ADDRESSING_MODE (EXTERNAL=GENERAL)) =
BEGIN
LIBRARY 'SYS$LIBRARY:STARLET';
EXTERNAL ROUTINE
LIB$PUT_OUTPUT;
GLOBAL ROUTINE HELLO_WORLD =
BEGIN
LIB$PUT_OUTPUT(%ASCID %STRING('Hello, world!'))
END;
END
ELUDOM
[edit] boo
See also GUI Section.
print "Hello, world!"
[edit] Burning Sand 2
WRITE ELEMENT:Earth 210 230 40 CENTER TEXT "Hello World!"
[edit] Casio FX-9750
This program will work on the fx-9750 graphing calculator and compatibles.
"Hello, world!"↵
or
Locate 1,1,"Hello, world!"↵
[edit] C/AL - MBS Navision
OBJECT Codeunit 50000 HelloWorld
{
PROPERTIES
{
OnRun=BEGIN
MESSAGE(Txt001);
END;
}
CODE
{
VAR
Txt001@1000000000 : TextConst 'ENU=Hello, world!';
BEGIN
{
Hello, world! in C/AL (Microsoft Business Solutions-Navision)
}
END.
}
}
[edit] C
#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
[edit] CCL
call echo("Hello, world!")
[edit] Ch
The above C code can run in Ch as examples. The simple one in Ch is:
printf("Hello, world!\n");
[edit] Chuck
<<<"Hello World">>>;
[edit] C#
See also GUI Section.
class HelloWorldApp { static void Main() { System.Console.WriteLine("Hello, world!"); } }
[edit] Chrome
namespace HelloWorld; interface type HelloClass = class public class method Main; end; implementation class method HelloClass.Main; begin System.Console.WriteLine('Hello, world!'); end; end.
[edit] C++
#include <iostream> int main() { std::cout << "Hello, world!\n"; }
or
#include <iostream> using namespace std; int main() { cout << "Hello, World!\n"; }
[edit] C++/CLI
int main()
{
System::Console::WriteLine("Hello, world!");
}
[edit] C++, Managed (.NET)
#using <mscorlib.dll>
using namespace System;
int wmain()
{
Console::WriteLine("Hello, world!");
}
[edit] LPC
void create()
{
write("Hello, world!\n");
}
[edit] ColdFusion (CFML)
<cfoutput>Hello, world!</cfoutput>
or simply
Hello, world!
[edit] COMAL
PRINT "Hello, world!"
[edit] CIL
.assembly Hello {}
.method public static void Main() cil managed
{
.entrypoint
.maxstack 1
ldstr "Hello, world!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
[edit] Clean
module hello Start = "Hello, world!"
[edit] CLIST
PROC 0 WRITE Hello, world!
[edit] Clipper
? "Hello, world!"
[edit] CLU
start_up = proc ()
po: stream := stream$primary_output ()
stream$putl (po, "Hello, world!")
end start_up
[edit] COBOL
IDENTIFICATION DIVISION.
PROGRAM ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY "Hello, world!"
STOP RUN.
The above is a very abbreviated and condensed version, which omits the author name and source and destination computer types.
[edit] D
import std.stdio ;
void main () {
writefln("Hello, world!");
}
[edit] D++
function main()
{
screenput "Hello, world!";
}
[edit] DC an arbitrary precision calculator
[Hello, world!]p
[edit] DCL batch
$ write sys$output "Hello, world!"
[edit] DOLL
this::operator()
{
import system.cstdio;
puts("Hello, world!");
}
[edit] Dream Maker
mob
Login()
..()
world << "Hello, world!"
[edit] Dylan
module: hello
format-out("Hello, world!\n");
[edit] EAScripting
There are a number of ways to write "Hello, world!" in EAScripting. The following are some ways
[edit] EAS 0.0.1.*
set disp to "Hello, world!" set dispto to item unit 5 //5 = default screen release disp into dispto.
This would be a pure system called by
import system ea.helloworld wait
[edit] Ed and Ex (Ed extended)
a Hello, world!! . p
[edit] Eiffel
class HELLO_WORLD
create make
feature
make is
do
io.put_string("Hello, world!%N")
end -- make
end -- class HELLO_WORLD
[edit] Erlang
- See also GUI section
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("Hello, world!\n").
[edit] Euphoria
puts(1, "Hello, world!")
[edit] F#
print_endline "Hello, world!"
[edit] Factor
"Hello, world!" print
[edit] Ferite
uses "console";
Console.println("Hello, world!");
[edit] filePro
@once: mesgbox "Hello, world!" ; exit