cofftest.asm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;Cannot be automatically tested because it differs every time,
  2. ;I guess because of a date/time field.
  3. ; test source file for assembling to COFF
  4. ; build with (under DJGPP, for example):
  5. ; nasm -f coff cofftest.asm
  6. ; gcc -o cofftest cofftest.c cofftest.o
  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. 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]
  34. SECTION .text
  35. ; prototype: long lrotate(long x, int num);
  36. _lrotate: ; [1]
  37. push ebp
  38. mov ebp,esp
  39. mov eax,[ebp+8]
  40. mov ecx,[ebp+12]
  41. .label rol eax,1 ; [4] [8]
  42. loop .label ; [9] [12]
  43. mov esp,ebp
  44. pop ebp
  45. ret
  46. ; prototype: void greet(void);
  47. _greet mov eax,[_integer] ; [14]
  48. inc eax
  49. mov [localint],eax ; [14]
  50. push dword [_commvar]
  51. mov eax,[localptr] ; [13]
  52. push dword [eax]
  53. push dword [_integer] ; [1] [14]
  54. push dword _printfstr ; [13]
  55. call _printf ; [11]
  56. add esp,16
  57. ret
  58. SECTION .data
  59. ; a string
  60. _asmstr db 'hello, world', 0 ; [2]
  61. ; a string for Printf
  62. _printfstr db "integer==%d, localint==%d, commvar=%d"
  63. db 10, 0
  64. ; some pointers
  65. localptr dd localint ; [5] [17]
  66. _textptr dd _greet ; [15]
  67. _selfptr dd _selfptr ; [16]
  68. SECTION .bss
  69. ; an integer
  70. _integer resd 1 ; [3]
  71. ; a local integer
  72. localint resd 1 ; [6]