NASM 2.00rc3
[nasm/avx512.git] / test / aoutso.asm
blobb95b66ee7375243fc6be2a4385a356043e00b7bd
1 ; test source file for assembling to NetBSD/FreeBSD a.out shared library
2 ; build with:
3 ; nasm -f aoutb aoutso.asm
4 ; ld -Bshareable -o aoutso.so aoutso.o
5 ; test with:
6 ; cc -o aoutso aouttest.c aoutso.so
7 ; ./aoutso
9 ; This file should test the following:
10 ; [1] Define and export a global text-section symbol
11 ; [2] Define and export a global data-section symbol
12 ; [3] Define and export a global BSS-section symbol
13 ; [4] Define a non-global text-section symbol
14 ; [5] Define a non-global data-section symbol
15 ; [6] Define a non-global BSS-section symbol
16 ; [7] Define a COMMON symbol
17 ; [8] Define a NASM local label
18 ; [9] Reference a NASM local label
19 ; [10] Import an external symbol
20 ; [11] Make a PC-relative call to an external symbol
21 ; [12] Reference a text-section symbol in the text section
22 ; [13] Reference a data-section symbol in the text section
23 ; [14] Reference a BSS-section symbol in the text section
24 ; [15] Reference a text-section symbol in the data section
25 ; [16] Reference a data-section symbol in the data section
26 ; [17] Reference a BSS-section symbol in the data section
28 BITS 32
29 EXTERN __GLOBAL_OFFSET_TABLE_
30 GLOBAL _lrotate:function ; [1]
31 GLOBAL _greet:function ; [1]
32 GLOBAL _asmstr:data _asmstr.end-_asmstr ; [2]
33 GLOBAL _textptr:data 4 ; [2]
34 GLOBAL _selfptr:data 4 ; [2]
35 GLOBAL _integer:data 4 ; [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 push ebx ; we'll use EBX for GOT, so save it
55 call .getgot
56 .getgot: pop ebx
57 add ebx,__GLOBAL_OFFSET_TABLE_ + $$ - .getgot wrt ..gotpc
58 mov eax,[ebx+_integer wrt ..got] ; [14]
59 mov eax,[eax]
60 inc eax
61 mov [ebx+localint wrt ..gotoff],eax ; [14]
62 mov eax,[ebx+_commvar wrt ..got]
63 push dword [eax]
64 mov eax,[ebx+localptr wrt ..gotoff] ; [13]
65 push dword [eax]
66 mov eax,[ebx+_integer wrt ..got] ; [1] [14]
67 push dword [eax]
68 lea eax,[ebx+_printfstr wrt ..gotoff]
69 push eax ; [13]
70 call _printf wrt ..plt ; [11]
71 add esp,16
72 pop ebx
73 ret
75 SECTION .data
77 ; a string
78 _asmstr db 'hello, world', 0 ; [2]
79 .end
81 ; a string for Printf
82 _printfstr db "integer==%d, localint==%d, commvar=%d"
83 db 10, 0
85 ; some pointers
86 localptr dd localint ; [5] [17]
87 _textptr dd _greet wrt ..sym ; [15]
88 _selfptr dd _selfptr wrt ..sym ; [16]
90 SECTION .bss
92 ; an integer
93 _integer resd 1 ; [3]
95 ; a local integer
96 localint resd 1 ; [6]