objtest.asm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  3. ; test source file for assembling to Microsoft 16-bit .OBJ
  4. ; build with (16-bit Microsoft C):
  5. ; nasm -f obj objtest.asm
  6. ; cl /AL objtest.obj objlink.c
  7. ; other compilers should work too, provided they handle large
  8. ; model in the same way as MS C
  9. ; This file should test the following:
  10. ; [1] Define and export a global symbol
  11. ; [2] Define a non-global symbol
  12. ; [3] Define a common symbol
  13. ; [4] Define a NASM local label
  14. ; [5] Reference a NASM local label
  15. ; [6] Import an external symbol
  16. ; [7] Make a PC-relative relocated reference
  17. ; [8] Reference a symbol in the same section as itself
  18. ; [9] Reference a symbol in a different segment from itself
  19. ; [10] Define a segment group
  20. ; [11] Take the offset of a symbol in a grouped segment w.r.t. its segment
  21. ; [12] Reserve uninitialised data space in a segment
  22. ; [13] Directly take the segment address of a segment
  23. ; [14] Directly take the segment address of a group
  24. ; [15] Use SEG on a non-external
  25. ; [16] Use SEG on an external
  26. bits 16
  27. global _bsssym ; [1]
  28. global _function ; [1]
  29. global _selfptr ; [1]
  30. global _selfptr2 ; [1]
  31. common _commvar 2 ; [3]
  32. extern _printf ; [6]
  33. group mygroup mybss mydata
  34. group mygroup2 mycode mycode2
  35. segment mycode private
  36. _function push bp
  37. mov bp,sp
  38. push ds
  39. mov ax,mygroup ; [14]
  40. mov ds,ax
  41. inc word [_bsssym] ; [9]
  42. mov ax,seg _commvar
  43. mov ds,ax
  44. dec word [_commvar]
  45. pop ds
  46. mov ax,[bp+6]
  47. mov dx,[bp+8]
  48. push dx
  49. push ax
  50. push dx
  51. push ax
  52. call far [cs:.printf] ; [5] [8]
  53. pop ax
  54. pop ax
  55. call trampoline ; [7]
  56. pop ax
  57. pop ax
  58. mov sp,bp
  59. pop bp
  60. retf
  61. .printf dw _printf, seg _printf ; [2] [4] [16]
  62. .printfd dd _printf, seg _printf ; [2] [4] [16]
  63. .printfq dq _printf, seg _printf ; [2] [4] [16]
  64. segment mycode2 private
  65. trampoline: pop ax
  66. push cs
  67. push ax
  68. jmp far _printf
  69. segment mybss private
  70. _bsssym resw 64 ; [12]
  71. segment mydata private
  72. _selfptr dw _selfptr, seg _selfptr ; [8] [15]
  73. _selfptr2 dw _selfptr2 wrt mydata, mydata ; [11] [13]