Merge branch 'master' into new-preproc
[nasm.git] / test / aouttest.asm
blob10d0e10a5997c18907b41bc6ebe51d6df13e3a39
1 ;Testname=unoptimized; Arguments=-O0 -faout -oaouttest.o; Files=stdout stderr aouttest.o
2 ;Testname=optimized; Arguments=-Ox -faout -oaouttest.o; Files=stdout stderr aouttest.o
4 ; test source file for assembling to a.out
5 ; build with:
6 ; nasm -f aout aouttest.asm
7 ; gcc -o aouttest aouttest.c aouttest.o
8 ; (assuming your gcc is a.out)
10 ; This file should test the following:
11 ; [1] Define and export a global text-section symbol
12 ; [2] Define and export a global data-section symbol
13 ; [3] Define and export a global BSS-section symbol
14 ; [4] Define a non-global text-section symbol
15 ; [5] Define a non-global data-section symbol
16 ; [6] Define a non-global BSS-section symbol
17 ; [7] Define a COMMON symbol
18 ; [8] Define a NASM local label
19 ; [9] Reference a NASM local label
20 ; [10] Import an external symbol
21 ; [11] Make a PC-relative call to an external symbol
22 ; [12] Reference a text-section symbol in the text section
23 ; [13] Reference a data-section symbol in the text section
24 ; [14] Reference a BSS-section symbol in the text section
25 ; [15] Reference a text-section symbol in the data section
26 ; [16] Reference a data-section symbol in the data section
27 ; [17] Reference a BSS-section symbol in the data section
29 BITS 32
30 GLOBAL _lrotate ; [1]
31 GLOBAL _greet ; [1]
32 GLOBAL _asmstr ; [2]
33 GLOBAL _textptr ; [2]
34 GLOBAL _selfptr ; [2]
35 GLOBAL _integer ; [3]
36 EXTERN _printf ; [10]
37 COMMON _commvar 4 ; [7]
39 SECTION .text
41 ; prototype: long lrotate(long x, int num);
42 _lrotate: ; [1]
43 push ebp
44 mov ebp,esp
45 mov eax,[ebp+8]
46 mov ecx,[ebp+12]
47 .label rol eax,1 ; [4] [8]
48 loop .label ; [9] [12]
49 mov esp,ebp
50 pop ebp
51 ret
53 ; prototype: void greet(void);
54 _greet mov eax,[_integer] ; [14]
55 inc eax
56 mov [localint],eax ; [14]
57 push dword [_commvar]
58 mov eax,[localptr] ; [13]
59 push dword [eax]
60 push dword [_integer] ; [1] [14]
61 push dword _printfstr ; [13]
62 call _printf ; [11]
63 add esp,16
64 ret
66 SECTION .data
68 ; a string
69 _asmstr db 'hello, world', 0 ; [2]
71 ; a string for Printf
72 _printfstr db "integer==%d, localint==%d, commvar=%d"
73 db 10, 0
75 ; some pointers
76 localptr dd localint ; [5] [17]
77 _textptr dd _greet ; [15]
78 _selfptr dd _selfptr ; [16]
80 SECTION .bss
82 ; an integer
83 _integer resd 1 ; [3]
85 ; a local integer
86 localint resd 1 ; [6]