“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 @\*`rl]
1tZ7%0R\g]
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 d/"%fpp^0G
XE#a#
以下是用不同语言写成的Hello World程序的几个例子: CMhl* dH
Ada 6o:b(v&Oo
with Ada.Text_Io; use Ada.Text_Io; $?Km3N\?v
procedure Hello is wI5(`_l{G
begin ahh&h1q7|
Put_Line ("Hello, world!"); Oj=g;iY
end Hello; wZUZ"Y}9
#]rfKHW9
G;ihm$Cad
汇编语言 QLm#7ms*y
,+P2B%2c
x86 CPU,DOS,TASM d Dg[ry
MODEL SMALL yac4\%ze
IDEAL :$=]*54`T
STACK 100H H\%^n<]#
"g5<j p
DATASEG y&n-8L_
HW DB 'Hello, world!$' */_$' /qV
`w8Ejm?n
CODESEG ?]%ZJd
MOV AX, @data i,h)VCc
MOV DS, AX xe4`D>LUo
MOV DX, OFFSET HW 9^?2{aP%
MOV AH, 09H ZGw6Bd_I
INT 21H %!\iII
MOV AX, 4C00H +@^FUt=tq
INT 21H {^@vCBE+
END 6:Hd `
%zKTrsMZ
`_iK`^(-
x86 CPU,GNU/Linux,NASM " k0gZb
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). Y=?Tm,z4
;Enter this into "hello.asm" then type: ]\1H=g%Ou
;"nasm -f elf hello.asm" r9Vt}]$a G
;"ld hello.o -o hello" $jg~a
;"./hello" ]>/oo =E
|jI|},I
section .data ;data section declaration gJH^f3
msg db 'Hello World!',0AH cd&sAK"
len equ $-msg ;string length @ N@
!Q
V8O-|7H$v
section .text ;code section declaration Eo`'6
3
global _start ;entry point (start of execution) Bh UGMK
_start: mov edx,len ;string length 5yL\@7u`
mov ecx,msg ;string start g [u*`]-;v
mov ebx,1 ;file handle: stdout :bq${
mov eax,4 ;sys_write {^.q6,l
int 80h ;kernel system call r,<p#4(>_
W5uC5C*,l
mov ebx,0 ;return value +<T361eyY
mov eax,1 ;sys_exit <CcSChCg
int 80h ;kernel system call hRQw]
v=_Ds<6n
en"\2+{Cg
x86 CPU,Windows,MASM32 cK- jN9U
.386 `.g'bZ<v/
.model flat,stdcall V
7oE\cxr
option casemap:none ]pWn%aGv*Y
;Include 文件定义 vX?C9Fr 2
include windows.inc 2"QcjFW%
include user32.inc *`40B6dEr
includelib user32.lib z%;_h-
include kernel32.inc lMmP]{.>$
includelib kernel32.lib 7/HX!y{WP
;数据段 2c'<rkA
.data *&z!y/
szCaption db 'A MessageBox!',0 7*kTu0m
szText db 'Hello,world!',0 7sU+:a
;代码段 qL?$u07<9'
.code ?X+PNw|pf
start: C1uV7t*\
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK {wl7&25
invoke ExitProcess,NULL -bgj<4R$p
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> G '%ZPh89
end start uf1s}/M
x9o(q`N
t~|`RMn"
AWK ?@^gpVK{
BEGIN { print "Hello, world!" } BS2'BS8
6"9(ce
KX
gSHN,8.
`
BASIC ,:{+-v(
传统版BASIC(例如GWBASIC): ;*{Ls#
SAU` u]E
10 PRINT "Hello, world!" NE><(02qW
20 END *Oq&g\K)
[4Q;5 'Dj
或在提示符输入: OGcW]i
BQ=JZ4&
?"Hello, world!":END ezA&cZ5
,b<m],p
现代版BASIC(例如Quick BASIC): sVH
w\_F$
Ri3*au/Q
Print "Hello, world!" h^YUu`P
zCS&