Sur Linux :
Avec comme command :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 ; hello.asm a first program for nasm for Linux, Intel, gcc ; ; assemble: nasm -f elf hello.asm ; link: gcc hello.o -o hello ; run: hello ; output is: Hello World SECTION .data ; data section msg: db "Hello World",10 ; the string to print, 10=cr len: equ $-msg ; "$" means "here" ; len is a value, not an address SECTION .text ; code section global main ; make label available to linker main: ; standard gcc entry point _start: mov edx,len ; arg3, length of string to print mov ecx,msg ; arg2, pointer to string mov ebx,1 ; arg1, where to write, screen mov eax,4 ; write sysout command to int 80 hex int 0x80 ; interrupt 80 hex, call kernel mov ebx,0 ; exit code, 0=normal mov eax,1 ; exit command to kernel int 0x80 ; interrupt 80 hex, call kernel
Pour Windows bonne question sur le net j'ai trouvé ceci (donc je n'ai pas pu testé personnellement) :Code:
1
2 nasm -f elf hello.asm gcc hello.o -o hello
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 ; Name: hello.asm ; Assemble: nasm.exe -f win32 hello.asm ; Link: ld hello.obj -emain -lkernel32 --enable-stdcall-fixup %SYSTEMROOT%\system32\kernel32.dll ; Run: a.exe BITS 32 extern _GetStdHandle extern _WriteFile extern _ExitProcess SECTION .data str: db "Hello world!" strlen equ $-str SECTION .text GLOBAL main main: ; Stack frame for NumberOfBytesWritten push ebp sub esp, 4 ; http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231.aspx ; HANDLE WINAPI GetStdHandle( ; _In_ DWORD nStdHandle ; ); push -11 call _GetStdHandle ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747.aspx ; BOOL WINAPI WriteFile( ; _In_ HANDLE hFile, ; _In_ LPCVOID lpBuffer, ; _In_ DWORD nNumberOfBytesToWrite, ; _Out_opt_ LPDWORD lpNumberOfBytesWritten, ; _Inout_opt_ LPOVERLAPPED lpOverlapped ; ); push 0 ; lpOverlapped, lea ebx, [ebp-4] ; EBX: address of NumberOfBytesWritten push ebx ; lpNumberOfBytesWritten, push strlen ; nNumberOfBytesToWrite push str ; lpBuffer, push eax ; hFile (result from GetStdHandle call _WriteFile ; ExitProcess (0) push 0 call _ExitProcess