“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 K!gocNOf
@EH@_EwYV
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 tCu9
D
D]K?ntS[*
以下是用不同语言写成的Hello World程序的几个例子: |1/?>=dDm
Ada :A,7D(H|
with Ada.Text_Io; use Ada.Text_Io; I&5cUj{GX-
procedure Hello is :n oZ
p:a
begin =Unu>p}2V
Put_Line ("Hello, world!"); _147d5
end Hello; CW~c<,"
}`uq:y
RNX>I,2sh
汇编语言 CbT ;#0
[ _&z+
x86 CPU,DOS,TASM 2c5)pIVEy
MODEL SMALL 8ZDWaq8^2N
IDEAL gy/bA
STACK 100H IZZ
$p{
kyUG+M
DATASEG 7nbaR~ZV
HW DB 'Hello, world!$'
e:6mz\J
lq)[
CODESEG Kp/l2?J"
MOV AX, @data {JW_ZJx
MOV DS, AX 9NqZ&S
MOV DX, OFFSET HW SdJkno
MOV AH, 09H t},71Ry
INT 21H 8|rlP
MOV AX, 4C00H 7*47mJyc
INT 21H A*? Qm
END Kuh)3/7
@G=_nZxv
iM{cr&0
x86 CPU,GNU/Linux,NASM <;NxmO<%\
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). :Y&h'FGZm
;Enter this into "hello.asm" then type: F=$U.K~1?
;"nasm -f elf hello.asm" .c _qMTm"
;"ld hello.o -o hello" r6}-EYq=
;"./hello" |TuFx=~5v
"%+9p6/
section .data ;data section declaration \0^Je>-:U
msg db 'Hello World!',0AH R%;dt<Dh
len equ $-msg ;string length 8jgamG
\-:4TuU
section .text ;code section declaration Z]^O=kX7k
global _start ;entry point (start of execution) %eE 6\f%g
_start: mov edx,len ;string length D}bCMN<
mov ecx,msg ;string start q_0,KOGW
mov ebx,1 ;file handle: stdout a8Z{-=)
mov eax,4 ;sys_write $eh>.c'&]
int 80h ;kernel system call us^J!
s7
c nV2}U/\
mov ebx,0 ;return value NKRH>2,
mov eax,1 ;sys_exit $(pVE}J
int 80h ;kernel system call ~"WN4
] U[4r9V
k)S'@>n{u
x86 CPU,Windows,MASM32 }zHG]k,j
.386 /3d6Og
.model flat,stdcall ?,*KA Gg%
option casemap:none ef
-PlGn
;Include 文件定义 CNyV6jb
include windows.inc fb|lWEw5h.
include user32.inc c]/&xRd
includelib user32.lib +v|]RgyW)
include kernel32.inc w0fFm"A|W
includelib kernel32.lib /QVhT
;数据段 rNX]tp{j
.data e>$E67h<~
szCaption db 'A MessageBox!',0 FeuqqZ\=&
szText db 'Hello,world!',0 <0H^2ekd
;代码段 F2mW<REg{
.code 6Y}Bza
start: !o8(9F
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK 7.C~ OrGR
invoke ExitProcess,NULL >/DlxYG?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IVSd,AR7yY
end start YRJw,xl
b`DPf@p^kc
x=VLRh%Gvl
AWK R8fB
8 )
BEGIN { print "Hello, world!" } 3[iHe+U(
mO^vKq4r.
IHNl`\Le
BASIC el^WBC3
传统版BASIC(例如GWBASIC): dL>8|
=^gZJ@
10 PRINT "Hello, world!" 2k"!o~s^
20 END z<n&P7k5j
"TePO7^m
或在提示符输入: SFa~j)9'n
kV+O|9
?"Hello, world!":END PkxhR;4
:HDU\|{^
现代版BASIC(例如Quick BASIC): 2< Q3-|/i
[V.#w|n
Print "Hello, world!" )nA fT0()0
Ct 30EZ
以下的语句在Quick BASIC中同样有效: zX ?@[OT
~!TRR.
? "Hello,world!" ##qs{s^]
:<>=,`vQD
~>|o3&G{
BCPL [78^:q-/0
GET "LIBHDR" uOprA`3
63y&M