1 ; test source file for assembling to ELF
3 ; nasm -f elf elftest.asm
4 ; gcc -o elftest elftest.c elftest.o
5 ; (assuming your gcc is ELF)
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
25 ; [18] Define a non-global rodata-section symbol
35 COMMON commvar
4 ; [7]
39 ; prototype: long lrotate(long x, int num);
45 .
label rol eax,1 ; [4] [8]
46 loop .
label ; [9] [12]
51 ; prototype: void greet(void);
52 greet
mov eax,[integer
] ; [14]
54 mov [localint
],eax ; [14]
56 mov eax,[localptr
] ; [13]
58 push dword [integer
] ; [1] [14]
59 push dword printfstr
; [13]
67 asmstr
db 'hello, world', 0 ; [2]
70 printfstr
db "integer==%d, localint==%d, commvar=%d"
74 localptr
dd localint
; [5] [17]
75 textptr
dd greet
; [15]
76 selfptr
dd selfptr
; [16]
87 readonly
dd readonly
; [18]