“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 -58q6yA
ddyX+.LMk
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 ?*%_:fB
A4cOnG,
以下是用不同语言写成的Hello World程序的几个例子: HA*L*:0
Ada ,T`,OZm
with Ada.Text_Io; use Ada.Text_Io; y?3.W
procedure Hello is ,|B-Nq
begin H#DvCw
Put_Line ("Hello, world!"); 8'HS$J;C
end Hello; tKeTHj;jO
q;")
uINdeq 7|F
汇编语言 C!a1.&HHZ7
9&5<ZC-D
x86 CPU,DOS,TASM ".tL+A[
MODEL SMALL -^lc-$0
IDEAL @(~:JP?KNC
STACK 100H UhpJG O
s0^(yEcq
DATASEG ,_fz)@)
HW DB 'Hello, world!$' 4a"Fu<q
u}gavG l
CODESEG AoeRoqg
MOV AX, @data 3_~iq>l
MOV DS, AX b.@a,:"
MOV DX, OFFSET HW =y4dR#R(\
MOV AH, 09H 6FQi=}O 1
INT 21H *Bq}.Yn
MOV AX, 4C00H s:Ml\['x
INT 21H 1XMR7liE
END 8&)v%TX
1(Ta*"(0Ip
G$+v |z
x86 CPU,GNU/Linux,NASM $KO2+^%y
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). uI)twry]@
;Enter this into "hello.asm" then type: RI0^#S_{
;"nasm -f elf hello.asm" 12KC4,C&1i
;"ld hello.o -o hello" o^\Pt<~W
;"./hello" 0(D^NtB7
/v8Q17O?e
section .data ;data section declaration 4
"HX1qP
msg db 'Hello World!',0AH *iEtXv
len equ $-msg ;string length a+E&{pV
Ve3z5d:^
section .text ;code section declaration UtQey ;w
global _start ;entry point (start of execution) >F7w]XH
_start: mov edx,len ;string length >sfg`4
mov ecx,msg ;string start >H!Mx_fDL
mov ebx,1 ;file handle: stdout BVNW1<_:
mov eax,4 ;sys_write #_@cI(P
int 80h ;kernel system call 3KkfQ{
XiE`_%NW
mov ebx,0 ;return value pn
gto
mov eax,1 ;sys_exit TZAd{EZa
int 80h ;kernel system call CwA_jOp
2gPqB*H
DH-M|~.sf^
x86 CPU,Windows,MASM32 IW3k{z
.386 %w*)7@,+-
.model flat,stdcall fkBL`[v)4
option casemap:none hMDd*<%l
;Include 文件定义 4^tSg#!V{
include windows.inc lmvp,BzC
include user32.inc h'):/}JPl
includelib user32.lib )U?_&LY)[M
include kernel32.inc RZm%4_p4s
includelib kernel32.lib wZiUzS;v
;数据段 :$MOdL[ir
.data I6W`yh`I)
szCaption db 'A MessageBox!',0 z1PwupXt1
szText db 'Hello,world!',0 <Kd(fFe
;代码段 Q +^&
.code -n|bi cP
start: 1cLtTE
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK d(T4Kd$r
invoke ExitProcess,NULL ~&i4