aouttest.asm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ;Testname=unoptimized; Arguments=-O0 -faout -oaouttest.o; Files=stdout stderr aouttest.o
  2. ;Testname=optimized; Arguments=-Ox -faout -oaouttest.o; Files=stdout stderr aouttest.o
  3. ; test source file for assembling to a.out
  4. ; build with:
  5. ; nasm -f aout aouttest.asm
  6. ; gcc -o aouttest aouttest.c aouttest.o
  7. ; (assuming your gcc is a.out)
  8. ; This file should test the following:
  9. ; [1] Define and export a global text-section symbol
  10. ; [2] Define and export a global data-section symbol
  11. ; [3] Define and export a global BSS-section symbol
  12. ; [4] Define a non-global text-section symbol
  13. ; [5] Define a non-global data-section symbol
  14. ; [6] Define a non-global BSS-section symbol
  15. ; [7] Define a COMMON symbol
  16. ; [8] Define a NASM local label
  17. ; [9] Reference a NASM local label
  18. ; [10] Import an external symbol
  19. ; [11] Make a PC-relative call to an external symbol
  20. ; [12] Reference a text-section symbol in the text section
  21. ; [13] Reference a data-section symbol in the text section
  22. ; [14] Reference a BSS-section symbol in the text section
  23. ; [15] Reference a text-section symbol in the data section
  24. ; [16] Reference a data-section symbol in the data section
  25. ; [17] Reference a BSS-section symbol in the data section
  26. BITS 32
  27. GLOBAL _lrotate ; [1]
  28. GLOBAL _greet ; [1]
  29. GLOBAL _asmstr ; [2]
  30. GLOBAL _textptr ; [2]
  31. GLOBAL _selfptr ; [2]
  32. GLOBAL _integer ; [3]
  33. EXTERN _printf ; [10]
  34. COMMON _commvar 4 ; [7]
  35. SECTION .text
  36. ; prototype: long lrotate(long x, int num);
  37. _lrotate: ; [1]
  38. push ebp
  39. mov ebp,esp
  40. mov eax,[ebp+8]
  41. mov ecx,[ebp+12]
  42. .label rol eax,1 ; [4] [8]
  43. loop .label ; [9] [12]
  44. mov esp,ebp
  45. pop ebp
  46. ret
  47. ; prototype: void greet(void);
  48. _greet mov eax,[_integer] ; [14]
  49. inc eax
  50. mov [localint],eax ; [14]
  51. push dword [_commvar]
  52. mov eax,[localptr] ; [13]
  53. push dword [eax]
  54. push dword [_integer] ; [1] [14]
  55. push dword _printfstr ; [13]
  56. call _printf ; [11]
  57. add esp,16
  58. ret
  59. SECTION .data
  60. ; a string
  61. _asmstr db 'hello, world', 0 ; [2]
  62. ; a string for Printf
  63. _printfstr db "integer==%d, localint==%d, commvar=%d"
  64. db 10, 0
  65. ; some pointers
  66. localptr dd localint ; [5] [17]
  67. _textptr dd _greet ; [15]
  68. _selfptr dd _selfptr ; [16]
  69. SECTION .bss
  70. ; an integer
  71. _integer resd 1 ; [3]
  72. ; a local integer
  73. localint resd 1 ; [6]