代码高亮居然成功了!感谢 Kate 编辑器!
1. 汇编(NASM,Intel 语法,仅 Linux x86)
section .data
msg: db "Hello, world!", 0Ah
.length: equ $ - msg
section .text
global _start
_start:
mov eax, 4h
mov ebx, 1h
mov ecx, msg
mov edx, msg.length
int 80h
mov eax, 1h
mov ebx, 0h
int 80h
2. 汇编(GAS,AT&T 语法,仅 Linux x86)
.data
msg: .ascii "Hello, world!\n"
msg.length = . - msg
.text
.global _start
_start:
movl $4, %eax
movl $1, %ebx
movl $msg, %ecx
movl $msg.length, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
3. C
#include <stdio.h> int main(void) { puts("Hello, world!"); return 0; }
4. C++
#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
5. Java
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, world!");
}
}
6. C#
public class Hello
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello, world!");
}
}
7. D
import std.stdio; int main(string[] args) { writefln("Hello, world!"); return 0; }
8. Objective-C
#import <Foundation/Foundation.h> int main(int argc, char *argv[]) { NSLog(@"Hello, world!"); return 0; }
9. Pascal
Program Hello;
Begin
WriteLn('Hello, world!');
End.
10. Bash
echo "Hello, world!"
11. DOS Batch
@echo off
echo Hello, world!
12. Qt/C++
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel label(QObject::tr("Hello, world!"));
label.show();
return app.exec();
}