blob: 88044c002a28f7f3092d378255a6efba8c6ea90e [file] [log] [blame]
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001; 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
5
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
24
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000025 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]
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000034
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000035 SECTION .text
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000036
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
48
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
61
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000062 SECTION .data
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000063
64; a string
65_asmstr db 'hello, world', 0 ; [2]
66
67; a string for Printf
68_printfstr db "integer==%d, localint==%d, commvar=%d"
69 db 10, 0
70
71; some pointers
72localptr dd localint ; [5] [17]
73_textptr dd _greet ; [15]
74_selfptr dd _selfptr ; [16]
75
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000076 SECTION .bss
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000077
78; an integer
79_integer resd 1 ; [3]
80
81; a local integer
82localint resd 1 ; [6]