“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 T
]hVO'z
O; 7`*}m
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 7+0Kg'^+n
c3W9"
以下是用不同语言写成的Hello World程序的几个例子: y4PR&^l?g
Ada 'c*Q/C;
with Ada.Text_Io; use Ada.Text_Io; ~,WG284
procedure Hello is eRKuy l
begin LuM:dJ
Put_Line ("Hello, world!"); rU=qr&f"B
end Hello; brx
7hI
}><VcouJ[
J]yUjnQ[h
汇编语言 -~\R.<+
`w` f[dU-
x86 CPU,DOS,TASM C#d.3t
MODEL SMALL [APwHIS
IDEAL HQJ_:x
Y
STACK 100H h+<vWo}H
m-Q!V+XQp
DATASEG i t.Lh'N;T
HW DB 'Hello, world!$' UmUw>+A
SR)G!9z_/
CODESEG Yj3j?.JJk
MOV AX, @data /'k4NXnW3
MOV DS, AX [-5%[ty9X
MOV DX, OFFSET HW Sio^FOTD
MOV AH, 09H 0tyoH3o/d
INT 21H z SDRZ!
MOV AX, 4C00H v._Q XcE
INT 21H \{``r
END :,Z'/e0&
>-J%=P
_;L%? -2c
x86 CPU,GNU/Linux,NASM }Q&zYC]d
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). h\| ~Q.kG
;Enter this into "hello.asm" then type: ^YG'p?r.s
;"nasm -f elf hello.asm" (k/[/`3ST
;"ld hello.o -o hello" `Sgj!/!F
;"./hello" "Zm**h.t
& mwQj<Z
section .data ;data section declaration d5Hp&tm
msg db 'Hello World!',0AH +a1Or
len equ $-msg ;string length H3\4&q
.'foS>W=t
section .text ;code section declaration tljZE)
global _start ;entry point (start of execution) <LL+\kfTZO
_start: mov edx,len ;string length (#I$4Px{
mov ecx,msg ;string start uq?((
mov ebx,1 ;file handle: stdout }p,#rOX:A
mov eax,4 ;sys_write (K9pr>le
int 80h ;kernel system call \ OPJ*/U
x-27rGN
mov ebx,0 ;return value &O8vI,M
mov eax,1 ;sys_exit riw0w
int 80h ;kernel system call 7q\&
RP[^1
2E5n07,
x86 CPU,Windows,MASM32 +g %h,@
.386 ! |4fww
.model flat,stdcall cxX/ b,
option casemap:none F{*{f =E!B
;Include 文件定义 "#}Uh
include windows.inc Q1f)uwh
include user32.inc (bhMo^3/*
includelib user32.lib %G6Q+LMwm
include kernel32.inc %!DdjC&5*
includelib kernel32.lib A c^hZ.qPz
;数据段 QguRU|y
.data 7`eg;s^
szCaption db 'A MessageBox!',0 @}9*rWJIE
szText db 'Hello,world!',0 S
$j"'K
;代码段 0\tV@ 6p2=
.code %!P^se
start: D+4oV6}~
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK Yr!@p Hy
invoke ExitProcess,NULL <&w(%<;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> zXX=WH
end start kXW5bR
CE,0@%6F*
78M%[7Cq<i
AWK .X1xpi%
BEGIN { print "Hello, world!" } {ovt
6C
b'AA*v,b
/UWv}f
0
BASIC 5>r2&72=
传统版BASIC(例如GWBASIC): `L~gERW#
lZ,w#sqbY
10 PRINT "Hello, world!" m8}c(GwcP
20 END J|$UAOEDa
8O^<