H. Peter Anvin | 733cbb3 | 2008-10-06 18:27:30 -0700 | [diff] [blame] | 1 | ;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 Elzen | 82fa68a | 2008-04-23 15:05:31 +0200 | [diff] [blame] | 3 | |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 4 | ; 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 Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 29 | bits 16 |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 30 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 31 | 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 Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 37 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 38 | group mygroup mybss mydata ; [10] |
| 39 | group mygroup2 mycode mycode2 ; [10] |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 40 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 41 | segment mycode private |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 42 | |
| 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] |
| 70 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 71 | segment mycode2 private |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 72 | |
| 73 | trampoline: pop ax |
| 74 | push cs |
| 75 | push ax |
| 76 | jmp far _printf |
| 77 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 78 | segment mybss private |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 79 | |
| 80 | _bsssym resw 64 ; [12] |
| 81 | |
H. Peter Anvin | d7ed89e | 2002-04-30 20:52:08 +0000 | [diff] [blame] | 82 | segment mydata private |
H. Peter Anvin | ea6e34d | 2002-04-30 20:51:32 +0000 | [diff] [blame] | 83 | |
| 84 | _selfptr dw _selfptr, seg _selfptr ; [8] [15] |
| 85 | _selfptr2 dw _selfptr2 wrt mydata, mydata ; [11] [13] |