“Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。 3@}rO~
pL [JGn
将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。 {[I]pm~n
&\Ze<u
以下是用不同语言写成的Hello World程序的几个例子: 2}\/_Y6
Ada qV$\E=%fhM
with Ada.Text_Io; use Ada.Text_Io; jw 4B^2}
procedure Hello is Ji#eA[
begin ?Yf0h_>
Put_Line ("Hello, world!"); MpNgp)%>
end Hello; Mg"e$m
{s7
3(B"
Q[n*ce7L0
汇编语言 #Sc9&DfX
e 48N[p
x86 CPU,DOS,TASM ^RI&`5g
MODEL SMALL rv?4S`Z,x$
IDEAL y2`},
STACK 100H `=Z3X(Kc
6 l,8ev
DATASEG /:Q
HW DB 'Hello, world!$' Ndz'^c
m[}@\y
CODESEG #c%FpR4
MOV AX, @data Q"vhl2RX
MOV DS, AX YB}m1g`
MOV DX, OFFSET HW ,{C
hHnJ%#
MOV AH, 09H A8X3|<n=
INT 21H agGgj>DDd
MOV AX, 4C00H ?E}9TQ
INT 21H JP,yRb\
END _C3O^/<n4V
kXroFLrY
E[ttamU
x86 CPU,GNU/Linux,NASM z&c|2L-u6
;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax). yZV Y3<]
;Enter this into "hello.asm" then type: e>2KW5.
;"nasm -f elf hello.asm" Qv
WvS9]
;"ld hello.o -o hello" JfsvK2I
;"./hello" )^`V{iD
m:D0O]2
section .data ;data section declaration -#Ys67,4N
msg db 'Hello World!',0AH 9RPZj>ezjA
len equ $-msg ;string length -A,UqEt
C
%i{{Y&l
section .text ;code section declaration m-2!r*(zt
global _start ;entry point (start of execution) _Ie?{5$ng`
_start: mov edx,len ;string length JT! Cb$!
mov ecx,msg ;string start ][dst@?8Oz
mov ebx,1 ;file handle: stdout 5gSe=|we*p
mov eax,4 ;sys_write Ay6]vU
int 80h ;kernel system call gHtflS
P0/Ctke;
mov ebx,0 ;return value `>- 56 %
mov eax,1 ;sys_exit < V*/1{
int 80h ;kernel system call ^4Uk'T7V
,<BV5~T.|
VGf&'nL@,
x86 CPU,Windows,MASM32 q 2P_37
.386 t2Px?S?
.model flat,stdcall TkR#Kzv380
option casemap:none t*J?#r
;Include 文件定义 P(.XB`
include windows.inc \S_Ae;
include user32.inc vScEQS$>
includelib user32.lib 1QPz|3f@\
include kernel32.inc ,A5}HRW%
includelib kernel32.lib ]XASim:A
;数据段 # w@FBFr@
.data h[;DRD!Z
szCaption db 'A MessageBox!',0 q|}O-A*wa
szText db 'Hello,world!',0 Y!`pF
;代码段 "g*`G<