|
1 |
| -%include "config.asm" |
2 |
| - |
3 |
| -global main |
4 |
| -extern puts |
| 1 | +; hello.asm a first program for nasm for Linux, Intel, gcc |
| 2 | +; |
| 3 | +; assemble: nasm -f elf -l hello.lst hello.asm |
| 4 | +; link: gcc -o hello hello.o |
| 5 | +; run: hello |
| 6 | +; output is: Hello World |
5 | 7 |
|
6 |
| -section .data |
7 |
| - hi db 'Hello, World', 0 |
| 8 | +%include "config.asm" |
8 | 9 |
|
9 | 10 | %ifdef FOO
|
10 | 11 | %define RETVAL HELLO
|
11 | 12 | %endif
|
12 | 13 |
|
13 |
| -section .text |
14 |
| -main: |
15 |
| - push rbp |
16 |
| - lea rdi, [rel hi] |
17 |
| - call puts wrt ..plt |
18 |
| - pop rbp |
19 |
| - mov ebx,RETVAL |
20 |
| - mov eax,1 |
21 |
| - int 0x80 |
| 14 | + SECTION .data ; data section |
| 15 | +msg: db "Hello World",10 ; the string to print, 10=cr |
| 16 | +len: equ $-msg ; "$" means "here" |
| 17 | + ; len is a value, not an address |
| 18 | + |
| 19 | + SECTION .text ; code section |
| 20 | + global main ; make label available to linker |
| 21 | +main: ; standard gcc entry point |
| 22 | + |
| 23 | + mov edx,len ; arg3, length of string to print |
| 24 | + mov ecx,msg ; arg2, pointer to string |
| 25 | + mov ebx,1 ; arg1, where to write, screen |
| 26 | + mov eax,4 ; write sysout command to int 80 hex |
| 27 | + int 0x80 ; interrupt 80 hex, call kernel |
| 28 | + |
| 29 | + mov ebx,RETVAL ; exit code, 0=normal |
| 30 | + mov eax,1 ; exit command to kernel |
| 31 | + int 0x80 ; interrupt 80 hex, call kernel |
0 commit comments