bintest.asm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ;Testname=unoptimized; Arguments=-O0 -fbin -obintest.bin; Files=stdout stderr bintest.bin
  2. ;Testname=optimized; Arguments=-Ox -fbin -obintest.bin; Files=stdout stderr bintest.bin
  3. ; test source file for assembling to binary files
  4. ; build with:
  5. ; nasm -f bin -o bintest.com bintest.asm
  6. ; When run (as a DOS .COM file), this program should print
  7. ; hello, world
  8. ; on two successive lines, then exit cleanly.
  9. ; This file should test the following:
  10. ; [1] Define a text-section symbol
  11. ; [2] Define a data-section symbol
  12. ; [3] Define a BSS-section symbol
  13. ; [4] Define a NASM local label
  14. ; [5] Reference a NASM local label
  15. ; [6] Reference a text-section symbol in the text section
  16. ; [7] Reference a data-section symbol in the text section
  17. ; [8] Reference a BSS-section symbol in the text section
  18. ; [9] Reference a text-section symbol in the data section
  19. ; [10] Reference a data-section symbol in the data section
  20. ; [11] Reference a BSS-section symbol in the data section
  21. BITS 16
  22. ORG 0x100
  23. SECTION .text
  24. jmp start ; [6]
  25. endX mov ax,0x4c00 ; [1]
  26. int 0x21
  27. start mov byte [bss_sym],',' ; [1] [8]
  28. mov bx,[bssptr] ; [7]
  29. mov al,[bx]
  30. mov bx,[dataptr] ; [7]
  31. mov [bx],al
  32. mov cx,2
  33. .loop mov dx,datasym ; [1] [4] [7]
  34. mov ah,9
  35. push cx
  36. int 0x21
  37. pop cx
  38. loop .loop ; [5] [6]
  39. mov bx,[textptr] ; [7]
  40. jmp bx
  41. SECTION .data
  42. datasym db 'hello world', 13, 10, '$' ; [2]
  43. bssptr dw bss_sym ; [2] [11]
  44. dataptr dw datasym+5 ; [2] [10]
  45. textptr dw endX ; [2] [9]
  46. SECTION .bss
  47. bss_sym resb 1 ; [3]