insns.dat: Add hle flag for DEC instruction
[nasm/nasm.git] / test / aoutso.asm
blobaab35a562019c6912b77ed21d8cfc139cdd597f9
1 ;Testname=unoptimized; Arguments=-O0 -faoutb -oaoutso.o; Files=stdout stderr aoutso.o
2 ;Testname=optimized; Arguments=-Ox -faoutb -oaoutso.o; Files=stdout stderr aoutso.o
4 ; test source file for assembling to NetBSD/FreeBSD a.out shared library
5 ; build with:
6 ; nasm -f aoutb aoutso.asm
7 ; ld -Bshareable -o aoutso.so aoutso.o
8 ; test with:
9 ; cc -o aoutso aouttest.c aoutso.so
10 ; ./aoutso
12 ; This file should test the following:
13 ; [1] Define and export a global text-section symbol
14 ; [2] Define and export a global data-section symbol
15 ; [3] Define and export a global BSS-section symbol
16 ; [4] Define a non-global text-section symbol
17 ; [5] Define a non-global data-section symbol
18 ; [6] Define a non-global BSS-section symbol
19 ; [7] Define a COMMON symbol
20 ; [8] Define a NASM local label
21 ; [9] Reference a NASM local label
22 ; [10] Import an external symbol
23 ; [11] Make a PC-relative call to an external symbol
24 ; [12] Reference a text-section symbol in the text section
25 ; [13] Reference a data-section symbol in the text section
26 ; [14] Reference a BSS-section symbol in the text section
27 ; [15] Reference a text-section symbol in the data section
28 ; [16] Reference a data-section symbol in the data section
29 ; [17] Reference a BSS-section symbol in the data section
31 BITS 32
32 EXTERN __GLOBAL_OFFSET_TABLE_
33 GLOBAL _lrotate:function ; [1]
34 GLOBAL _greet:function ; [1]
35 GLOBAL _asmstr:data _asmstr.end-_asmstr ; [2]
36 GLOBAL _textptr:data 4 ; [2]
37 GLOBAL _selfptr:data 4 ; [2]
38 GLOBAL _integer:data 4 ; [3]
39 EXTERN _printf ; [10]
40 COMMON _commvar 4 ; [7]
42 SECTION .text
44 ; prototype: long lrotate(long x, int num);
45 _lrotate: ; [1]
46 push ebp
47 mov ebp,esp
48 mov eax,[ebp+8]
49 mov ecx,[ebp+12]
50 .label rol eax,1 ; [4] [8]
51 loop .label ; [9] [12]
52 mov esp,ebp
53 pop ebp
54 ret
56 ; prototype: void greet(void);
57 _greet push ebx ; we'll use EBX for GOT, so save it
58 call .getgot
59 .getgot: pop ebx
60 add ebx,__GLOBAL_OFFSET_TABLE_ + $$ - .getgot wrt ..gotpc
61 mov eax,[ebx+_integer wrt ..got] ; [14]
62 mov eax,[eax]
63 inc eax
64 mov [ebx+localint wrt ..gotoff],eax ; [14]
65 mov eax,[ebx+_commvar wrt ..got]
66 push dword [eax]
67 mov eax,[ebx+localptr wrt ..gotoff] ; [13]
68 push dword [eax]
69 mov eax,[ebx+_integer wrt ..got] ; [1] [14]
70 push dword [eax]
71 lea eax,[ebx+_printfstr wrt ..gotoff]
72 push eax ; [13]
73 call _printf wrt ..plt ; [11]
74 add esp,16
75 pop ebx
76 ret
78 SECTION .data
80 ; a string
81 _asmstr db 'hello, world', 0 ; [2]
82 .end
84 ; a string for Printf
85 _printfstr db "integer==%d, localint==%d, commvar=%d"
86 db 10, 0
88 ; some pointers
89 localptr dd localint ; [5] [17]
90 _textptr dd _greet wrt ..sym ; [15]
91 _selfptr dd _selfptr wrt ..sym ; [16]
93 SECTION .bss
95 ; an integer
96 _integer resd 1 ; [3]
98 ; a local integer
99 localint resd 1 ; [6]