blob: c68f7cbbe9dca3ebb388e1ad4822fed3cf9c7264 [file] [log] [blame]
H. Peter Anvin733cbb32008-10-06 18:27:30 -07001;Testname=unoptimized; Arguments=-O0 -fobj -oobj.o; Files=stdout stderr obj.o
2;Testname=optimized; Arguments=-Ox -fobj -oobj.o; Files=stdout stderr obj.o
Victor van den Elzen82fa68a2008-04-23 15:05:31 +02003
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00004; test source file for assembling to Microsoft 16-bit .OBJ
5; build with (16-bit Microsoft C):
6; nasm -f obj objtest.asm
7; cl /AL objtest.obj objlink.c
8; other compilers should work too, provided they handle large
9; model in the same way as MS C
10
11; This file should test the following:
12; [1] Define and export a global symbol
13; [2] Define a non-global symbol
14; [3] Define a common symbol
15; [4] Define a NASM local label
16; [5] Reference a NASM local label
17; [6] Import an external symbol
18; [7] Make a PC-relative relocated reference
19; [8] Reference a symbol in the same section as itself
20; [9] Reference a symbol in a different segment from itself
21; [10] Define a segment group
22; [11] Take the offset of a symbol in a grouped segment w.r.t. its segment
23; [12] Reserve uninitialised data space in a segment
24; [13] Directly take the segment address of a segment
25; [14] Directly take the segment address of a group
26; [15] Use SEG on a non-external
27; [16] Use SEG on an external
28
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000029 bits 16
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000030
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000031 global _bsssym ; [1]
32 global _function ; [1]
33 global _selfptr ; [1]
34 global _selfptr2 ; [1]
35 common _commvar 2 ; [3]
36 extern _printf ; [6]
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000037
H. Peter Anvina7b6bfc2017-05-03 17:32:02 -070038 group mygroup mybss mydata
39 group mygroup2 mycode mycode2
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000040
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000041 segment mycode private
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000042
43_function push bp
44 mov bp,sp
45 push ds
46 mov ax,mygroup ; [14]
47 mov ds,ax
48 inc word [_bsssym] ; [9]
49 mov ax,seg _commvar
50 mov ds,ax
51 dec word [_commvar]
52 pop ds
53 mov ax,[bp+6]
54 mov dx,[bp+8]
55 push dx
56 push ax
57 push dx
58 push ax
59 call far [cs:.printf] ; [5] [8]
60 pop ax
61 pop ax
62 call trampoline ; [7]
63 pop ax
64 pop ax
65 mov sp,bp
66 pop bp
67 retf
68
69.printf dw _printf, seg _printf ; [2] [4] [16]
H. Peter Anvina7b6bfc2017-05-03 17:32:02 -070070.printfd dd _printf, seg _printf ; [2] [4] [16]
71.printfq dq _printf, seg _printf ; [2] [4] [16]
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000072
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000073 segment mycode2 private
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000074
75trampoline: pop ax
76 push cs
77 push ax
78 jmp far _printf
79
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000080 segment mybss private
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000081
82_bsssym resw 64 ; [12]
83
H. Peter Anvind7ed89e2002-04-30 20:52:08 +000084 segment mydata private
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000085
86_selfptr dw _selfptr, seg _selfptr ; [8] [15]
87_selfptr2 dw _selfptr2 wrt mydata, mydata ; [11] [13]