phash.ph: yet another attempt at getting Perl to behave, arithmetically
[nasm/avx512.git] / test / aouttest.asm
bloba11824f679560a7bcb84ef936597b8429c7579dc
1 ; test source file for assembling to a.out
2 ; build with:
3 ; nasm -f aout aouttest.asm
4 ; gcc -o aouttest aouttest.c aouttest.o
5 ; (assuming your gcc is a.out)
7 ; This file should test the following:
8 ; [1] Define and export a global text-section symbol
9 ; [2] Define and export a global data-section symbol
10 ; [3] Define and export a global BSS-section symbol
11 ; [4] Define a non-global text-section symbol
12 ; [5] Define a non-global data-section symbol
13 ; [6] Define a non-global BSS-section symbol
14 ; [7] Define a COMMON symbol
15 ; [8] Define a NASM local label
16 ; [9] Reference a NASM local label
17 ; [10] Import an external symbol
18 ; [11] Make a PC-relative call to an external symbol
19 ; [12] Reference a text-section symbol in the text section
20 ; [13] Reference a data-section symbol in the text section
21 ; [14] Reference a BSS-section symbol in the text section
22 ; [15] Reference a text-section symbol in the data section
23 ; [16] Reference a data-section symbol in the data section
24 ; [17] Reference a BSS-section symbol in the data section
26 BITS 32
27 GLOBAL _lrotate ; [1]
28 GLOBAL _greet ; [1]
29 GLOBAL _asmstr ; [2]
30 GLOBAL _textptr ; [2]
31 GLOBAL _selfptr ; [2]
32 GLOBAL _integer ; [3]
33 EXTERN _printf ; [10]
34 COMMON _commvar 4 ; [7]
36 SECTION .text
38 ; prototype: long lrotate(long x, int num);
39 _lrotate: ; [1]
40 push ebp
41 mov ebp,esp
42 mov eax,[ebp+8]
43 mov ecx,[ebp+12]
44 .label rol eax,1 ; [4] [8]
45 loop .label ; [9] [12]
46 mov esp,ebp
47 pop ebp
48 ret
50 ; prototype: void greet(void);
51 _greet mov eax,[_integer] ; [14]
52 inc eax
53 mov [localint],eax ; [14]
54 push dword [_commvar]
55 mov eax,[localptr] ; [13]
56 push dword [eax]
57 push dword [_integer] ; [1] [14]
58 push dword _printfstr ; [13]
59 call _printf ; [11]
60 add esp,16
61 ret
63 SECTION .data
65 ; a string
66 _asmstr db 'hello, world', 0 ; [2]
68 ; a string for Printf
69 _printfstr db "integer==%d, localint==%d, commvar=%d"
70 db 10, 0
72 ; some pointers
73 localptr dd localint ; [5] [17]
74 _textptr dd _greet ; [15]
75 _selfptr dd _selfptr ; [16]
77 SECTION .bss
79 ; an integer
80 _integer resd 1 ; [3]
82 ; a local integer
83 localint resd 1 ; [6]