NASM 0.94
[nasm/avx512.git] / test / cofftest.asm
blob88044c002a28f7f3092d378255a6efba8c6ea90e
1 ; test source file for assembling to COFF
2 ; build with (under DJGPP, for example):
3 ; nasm -f coff cofftest.asm
4 ; gcc -o cofftest cofftest.c cofftest.o
6 ; This file should test the following:
7 ; [1] Define and export a global text-section symbol
8 ; [2] Define and export a global data-section symbol
9 ; [3] Define and export a global BSS-section symbol
10 ; [4] Define a non-global text-section symbol
11 ; [5] Define a non-global data-section symbol
12 ; [6] Define a non-global BSS-section symbol
13 ; [7] Define a COMMON symbol
14 ; [8] Define a NASM local label
15 ; [9] Reference a NASM local label
16 ; [10] Import an external symbol
17 ; [11] Make a PC-relative call to an external symbol
18 ; [12] Reference a text-section symbol in the text section
19 ; [13] Reference a data-section symbol in the text section
20 ; [14] Reference a BSS-section symbol in the text section
21 ; [15] Reference a text-section symbol in the data section
22 ; [16] Reference a data-section symbol in the data section
23 ; [17] Reference a BSS-section symbol in the data section
25 BITS 32
26 GLOBAL _lrotate ; [1]
27 GLOBAL _greet ; [1]
28 GLOBAL _asmstr ; [2]
29 GLOBAL _textptr ; [2]
30 GLOBAL _selfptr ; [2]
31 GLOBAL _integer ; [3]
32 EXTERN _printf ; [10]
33 COMMON _commvar 4 ; [7]
35 SECTION .text
37 ; prototype: long lrotate(long x, int num);
38 _lrotate: ; [1]
39 push ebp
40 mov ebp,esp
41 mov eax,[ebp+8]
42 mov ecx,[ebp+12]
43 .label rol eax,1 ; [4] [8]
44 loop .label ; [9] [12]
45 mov esp,ebp
46 pop ebp
47 ret
49 ; prototype: void greet(void);
50 _greet mov eax,[_integer] ; [14]
51 inc eax
52 mov [localint],eax ; [14]
53 push dword [_commvar]
54 mov eax,[localptr] ; [13]
55 push dword [eax]
56 push dword [_integer] ; [1] [14]
57 push dword _printfstr ; [13]
58 call _printf ; [11]
59 add esp,16
60 ret
62 SECTION .data
64 ; a string
65 _asmstr db 'hello, world', 0 ; [2]
67 ; a string for Printf
68 _printfstr db "integer==%d, localint==%d, commvar=%d"
69 db 10, 0
71 ; some pointers
72 localptr dd localint ; [5] [17]
73 _textptr dd _greet ; [15]
74 _selfptr dd _selfptr ; [16]
76 SECTION .bss
78 ; an integer
79 _integer resd 1 ; [3]
81 ; a local integer
82 localint resd 1 ; [6]