blob: 6b845e2ee3f3e6479fb5aa3bc95c603e030c42d0 [file] [log] [blame]
Victor van den Elzen82fa68a2008-04-23 15:05:31 +02001;Cannot be automatically tested because it differs every time,
2;I guess because of a date/time field.
3
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00004; 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
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000028 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]
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000037
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000038 SECTION .text
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000039
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
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000065 SECTION .data
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000066
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
75localptr dd localint ; [5] [17]
76_textptr dd _greet ; [15]
77_selfptr dd _selfptr ; [16]
78
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000079 SECTION .bss
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000080
81; an integer
82_integer resd 1 ; [3]
83
84; a local integer
85localint resd 1 ; [6]