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[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 _druck] ; [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 51 mov eax,[_integer] ; [14] 52 inc eax 53 mov [localint],eax ; [14] 54 push dword [_commvar] 55 mov eax,[localptr] ; [13] 56 push dword [eax] 57 push dword [_integer] ; [1] [14] 58 push dword _printfstr ; [13] 59 call _druck ; [11] 60 add esp,16 61 ret 62 63; some internal calls 64 call _greet 65 call _lrotate.label 66 67[SECTION .data] 68 69; a string 70_asmstr db 'hello, world', 0 ; [2] 71 72; a string for Printf 73_printfstr db "integer==%d, localint==%d, commvar=%d" 74 db 10, 0 75 76; some pointers 77localptr dd localint ; [5] [17] 78_textptr dd _greet ; [15] 79_selfptr dd _selfptr ; [16] 80 81[SECTION .bss] 82 83; an integer 84_integer resd 1 ; [3] 85 86; a local integer 87localint resd 1 ; [6] 88