1# test source file for assembling to MACH-O 
2# build with :
3#    yasm -f macho machotest.asm
4#    gcc -o machotest machotest.c machotest.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 (note: printf replaced by another call)
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.globl _lrotate	# [1]
26.globl _greet		# [1]
27.globl _asmstr		# [2]
28.globl _textptr	# [2]
29.globl _selfptr	# [2]
30.globl _integer	# [3]
31#.extern _druck		# [10]
32.comm _commvar, 4	# [7]
33
34.text
35
36# prototype: long lrotate(long x, int num);
37_lrotate:			# [1]
38	  pushl %ebp
39	  movl %esp, %ebp
40	  movl 8(%ebp), %eax
41	  movl 12(%ebp), %ecx
42Llabel:	  roll %eax		# [4] [8]
43	  loop Llabel		# [9] [12]
44	  movl %ebp, %esp
45	  popl %ebp
46	  ret
47
48# prototype: void greet(void);
49_greet:
50	  movl _integer, %eax	# [14]
51	  incl %eax
52	  movl %eax, localint	# [14]
53	  pushl _commvar
54	  movl localptr, %eax	# [13]
55	  pushl (%eax)
56	  pushl _integer	# [1] [14]
57	  pushl _printfstr	# [13]
58	  calll _druck		# [11]
59	  addl 16, %esp
60	  ret
61
62.data
63
64# a string
65_asmstr: .asciz "hello, world"	# [2]
66
67# a string for Printf 
68_printfstr: .asciz "integer==%d, localint==%d, commvar=%d\n"
69
70# some pointers
71localptr:  .long localint	# [5] [17]
72_textptr:  .long _greet		# [15]
73_selfptr:  .long _selfptr	# [16]
74
75# an integer
76.lcomm _integer, 4		# [3]
77
78# a local integer
79.lcomm localint, 4		# [6]
80