10554
|
1 ;Cannot be automatically tested because it differs every time,
|
|
2 ;I guess because of a date/time field.
|
|
3
|
|
4 ; test source file for assembling to COFF
|
|
5 ; build with (under DJGPP, for example):
|
|
6 ; nasm -f coff cofftest.asm
|
|
7 ; gcc -o cofftest cofftest.c cofftest.o
|
|
8
|
|
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
|
|
27
|
|
28 BITS 32
|
|
29 GLOBAL _lrotate ; [1]
|
|
30 GLOBAL _greet ; [1]
|
|
31 GLOBAL _asmstr ; [2]
|
|
32 GLOBAL _textptr ; [2]
|
|
33 GLOBAL _selfptr ; [2]
|
|
34 GLOBAL _integer ; [3]
|
|
35 EXTERN _printf ; [10]
|
|
36 COMMON _commvar 4 ; [7]
|
|
37
|
|
38 SECTION .text
|
|
39
|
|
40 ; prototype: long lrotate(long x, int num);
|
|
41 _lrotate: ; [1]
|
|
42 push ebp
|
|
43 mov ebp,esp
|
|
44 mov eax,[ebp+8]
|
|
45 mov ecx,[ebp+12]
|
|
46 .label rol eax,1 ; [4] [8]
|
|
47 loop .label ; [9] [12]
|
|
48 mov esp,ebp
|
|
49 pop ebp
|
|
50 ret
|
|
51
|
|
52 ; prototype: void greet(void);
|
|
53 _greet mov eax,[_integer] ; [14]
|
|
54 inc eax
|
|
55 mov [localint],eax ; [14]
|
|
56 push dword [_commvar]
|
|
57 mov eax,[localptr] ; [13]
|
|
58 push dword [eax]
|
|
59 push dword [_integer] ; [1] [14]
|
|
60 push dword _printfstr ; [13]
|
|
61 call _printf ; [11]
|
|
62 add esp,16
|
|
63 ret
|
|
64
|
|
65 SECTION .data
|
|
66
|
|
67 ; a string
|
|
68 _asmstr db 'hello, world', 0 ; [2]
|
|
69
|
|
70 ; a string for Printf
|
|
71 _printfstr db "integer==%d, localint==%d, commvar=%d"
|
|
72 db 10, 0
|
|
73
|
|
74 ; some pointers
|
|
75 localptr dd localint ; [5] [17]
|
|
76 _textptr dd _greet ; [15]
|
|
77 _selfptr dd _selfptr ; [16]
|
|
78
|
|
79 SECTION .bss
|
|
80
|
|
81 ; an integer
|
|
82 _integer resd 1 ; [3]
|
|
83
|
|
84 ; a local integer
|
|
85 localint resd 1 ; [6]
|