Home | History | Annotate | Download | only in tests
      1 ; test source file for assembling to COFF
      2 ; build with (under DJGPP, for example):
      3 ;    yasm -f coff cofftest.asm
      4 ;    gcc -o cofftest cofftest.c cofftest.o
      5 
      6 ; This file should test the following:
      7 ; [1] Define and export a global text-section symbol
      8 ; [2] Define and export a global data-section symbol
      9 ; [3] Define and export a global BSS-section symbol
     10 ; [4] Define a non-global text-section symbol
     11 ; [5] Define a non-global data-section symbol
     12 ; [6] Define a non-global BSS-section symbol
     13 ; [7] Define a COMMON symbol
     14 ; [8] Define a NASM local label
     15 ; [9] Reference a NASM local label
     16 ; [10] Import an external symbol
     17 ; [11] Make a PC-relative call to an external symbol
     18 ; [12] Reference a text-section symbol in the text section
     19 ; [13] Reference a data-section symbol in the text section
     20 ; [14] Reference a BSS-section symbol in the text section
     21 ; [15] Reference a text-section symbol in the data section
     22 ; [16] Reference a data-section symbol in the data section
     23 ; [17] Reference a BSS-section symbol in the data section
     24 
     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 
     35 [SECTION .text]
     36 
     37 ; prototype: long lrotate(long x, int num);
     38 _lrotate:			; [1]
     39 	  push ebp
     40 	  mov ebp,esp
     41 	  mov eax,[ebp+8]
     42 	  mov ecx,[ebp+12]
     43 .label	  rol eax,1		; [4] [8]
     44 	  loop .label		; [9] [12]
     45 	  mov esp,ebp
     46 	  pop ebp
     47 	  ret
     48 
     49 ; prototype: void greet(void);
     50 _greet	  mov eax,[_integer]	; [14]
     51 	  inc eax
     52 	  mov [localint],eax	; [14]
     53 	  push dword [_commvar]
     54 	  mov eax,[localptr]	; [13]
     55 	  push dword [eax]
     56 	  push dword [_integer]	; [1] [14]
     57 	  push dword _printfstr	; [13]
     58 	  call _printf		; [11]
     59 	  add esp,16
     60 	  ret
     61 
     62 [SECTION .data]
     63 
     64 ; a string
     65 _asmstr	  db 'hello, world', 0	; [2]
     66 
     67 ; a string for Printf
     68 _printfstr db "integer==%d, localint==%d, commvar=%d"
     69 	  db 10, 0
     70 
     71 ; some pointers
     72 localptr  dd localint		; [5] [17]
     73 _textptr  dd _greet		; [15]
     74 _selfptr  dd _selfptr		; [16]
     75 
     76 [SECTION .bss]
     77 
     78 ; an integer
     79 _integer  resd 1		; [3]
     80 
     81 ; a local integer
     82 localint  resd 1		; [6]
     83