| 1 |
;Testname=aout; Arguments=-faout -olnxhello.o -Ox; Files=stdout stderr lnxhello.o |
| 2 |
;Testname=aoutb; Arguments=-faoutb -olnxhello.o -Ox; Files=stdout stderr lnxhello.o |
| 3 |
;Testname=as86; Arguments=-fas86 -olnxhello.o -Ox; Files=stdout stderr lnxhello.o |
| 4 |
;Testname=elf32; Arguments=-felf32 -olnxhello.o -Ox; Files=stdout stderr lnxhello.o |
| 5 |
|
| 6 |
; |
| 7 |
; Assembly "Hello, World!" for Linux |
| 8 |
; |
| 9 |
|
| 10 |
|
| 11 |
; Properly defined in <sys/syscall.h> |
| 12 |
%define SYS_exit 1 |
| 13 |
%define SYS_write 4 |
| 14 |
|
| 15 |
section .text |
| 16 |
|
| 17 |
global _start |
| 18 |
_start: |
| 19 |
; gdb doesn't like to stop at the entry point address, so |
| 20 |
; we put a nop here for pure convenience |
| 21 |
nop |
| 22 |
|
| 23 |
|
| 24 |
write_hello: |
| 25 |
mov edx, hello_len |
| 26 |
mov ecx, hello |
| 27 |
|
| 28 |
.loop: |
| 29 |
mov eax, SYS_write |
| 30 |
mov ebx, 1 ; stdout |
| 31 |
int 80h |
| 32 |
|
| 33 |
cmp eax, -4096 |
| 34 |
ja error |
| 35 |
|
| 36 |
add ecx, eax |
| 37 |
sub edx, eax |
| 38 |
jnz .loop |
| 39 |
|
| 40 |
ok: |
| 41 |
mov eax, SYS_exit |
| 42 |
xor ebx, ebx |
| 43 |
int 80h |
| 44 |
hlt |
| 45 |
|
| 46 |
error: |
| 47 |
mov eax, SYS_exit |
| 48 |
mov ebx, 1 ; Error |
| 49 |
int 80h |
| 50 |
hlt |
| 51 |
|
| 52 |
section .rodata |
| 53 |
hello: db "Hello, World!", 10 |
| 54 |
hello_len equ $-hello |