“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 =}YaV@g<f
lxOUV? m^N
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 bODyJ7=[
,IQ%7*f;O_
以下是用不同语言写成的Hello World程序的几个例子: ')~[J$qz
Ada 5*r5?ne
with Ada.Text_Io; use Ada.Text_Io; (Ei} :6,}
procedure Hello is Ox"SQ`nSj'
begin 3+WostOx
Put_Line ("Hello, world!"); SI/p8 ^
end Hello; qiyJ4^1
!_j6\r=
(/3E,6gMk^
汇编语言 0*8uo
Wt&
>Mk#19j[/
x86 CPU,DOS,TASM ny[\yj4F
MODEL SMALL G0pqiU6
IDEAL vU,;asgy
STACK 100H c"^g*i2&0
MnD^jcx
DATASEG =FXq=x%9+
HW DB 'Hello, world!$' R(<_p"9(
}i@%$Ixsn
CODESEG Gque@u
MOV AX, @data T6Ks]6m_
MOV DS, AX lyQNE3
MOV DX, OFFSET HW vB1nj<]&z
MOV AH, 09H E sx`UG|
INT 21H L$
ZZ]?7j
MOV AX, 4C00H 38gEto#q
INT 21H !vH={40 ]
END oq9gG)F
.+dego:
wGAeOD
x86 CPU,GNU/Linux,NASM yU< "tg E
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). 2, r{zJ8
;Enter this into "hello.asm" then type: <l"rn M%
;"nasm -f elf hello.asm" O*+,KKPt
;"ld hello.o -o hello" yu@u0vlc
;"./hello" 5r(Y,m"?
geEETb}+y
section .data ;data section declaration "c0Nv8_G
msg db 'Hello World!',0AH W)fh}|.5
len equ $-msg ;string length ]ppws3*Pa
6eHw\$/
section .text ;code section declaration ,ku3;58O<
global _start ;entry point (start of execution) `ls^fnJTpf
_start: mov edx,len ;string length _"'0^F$I
mov ecx,msg ;string start :`20i*
mov ebx,1 ;file handle: stdout 'v'=t<wgl
mov eax,4 ;sys_write -q}I;
cH
int 80h ;kernel system call XCQPVSh
\s">trXwX
mov ebx,0 ;return value vC ISd
mov eax,1 ;sys_exit >`u/#mrd
int 80h ;kernel system call 2RC@Fu~zaU
vFgX]&bE
\K(QE ~y'W
x86 CPU,Windows,MASM32 }@Ou]o
.386
zv HeoM,
.model flat,stdcall #JW~ &;
option casemap:none ^)0b= (.
;Include 文件定义 K1[(%<Gp
include windows.inc kCZxv"Ts
include user32.inc FG6mh,C!
includelib user32.lib &&
E)
include kernel32.inc h$rk]UM/Q
includelib kernel32.lib <)ltvo(
;数据段 RqRyZ*n
.data e{7"7wn=
szCaption db 'A MessageBox!',0 #>\%7b59>
szText db 'Hello,world!',0 &1$|KbmV4
;代码段 ZIikDih1
.code ".Sa[A;~
start: l
F*x\AT
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK M5<cHE
invoke ExitProcess,NULL !+Us) 'L
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 56T{ JTo
end start Q_M:v
^.~m4t`U
^P}c0}^
AWK ]aTF0 R
BEGIN { print "Hello, world!" } 4+'d">+|
"E}38
iK3gw<g
BASIC WDq~mi
传统版BASIC(例如GWBASIC):
-
j_
R"V^%z;8o
10 PRINT "Hello, world!" %Tm8sQ)1
20 END drK &
l~c# X3E
或在提示符输入: w!~85""
pCt0[R;?
?"Hello, world!":END /j:fc?yv
gO,2:,
现代版BASIC(例如Quick BASIC): KG9FR*"
u RPvo}!=1
Print "Hello, world!" ] R-<v&O
XYdr~/[HPy
以下的语句在Quick BASIC中同样有效: mdy+ >e<
c3q @]|aI
? "Hello,world!" &