Tüm montaj kodu örneklerinin 32 bit Linux ortamı için yazıldığı bir kitap okuyorum ve 64 bit Mac kullanıyorum. _start
'u start
olarak değiştirdikten sonra NASM ile aşağıdaki programı derleyebildim. Ancak, yürütülebilir dosyayı çalıştırdığımda beklediğim gibi hello world
yazmıyor. Bunu 64 bit Mac üzerinde çalışacak şekilde derlemek için NASM'ye geçmek için bir seçenek var mı?x86_64 ortamı için 32 bit derlemeyi derlemek için NASM kullanın
Denedim: takip
nasm -f macho32 helloworld.asm
ve
nasm -f macho helloworld.asm
:
ld helloworld.o -o helloworld
Benim kod geçerli:
section .data ; data segment
msg db "Hello, world!", 0x0a ; the string and newline char
section .text ; text segment
global start ; Default entry point for ELF linking
start:
; SYSCALL: write(1, msg, 14)
mov eax, 4 ; put 4 into eax, since write is syscall #4
mov ebx, 1 ; put 1 into ebx, since stdout is 1
mov ecx, msg ; put the address of the string into ecx
mov edx, 14 ; put 14 into edx, since our string is 14 bytes
int 0x80 ; Call the kernel to make the system call happen
; SYSCALL: exit(0)
mov eax, 1 ; put 1 into eax, since exit is syscall #1
mov ebx, 0 ; exit with success
int 0x80 ; do the syscall
'int 0x80', Linux'taki gibi OS/X'de aynı şekilde çalışmaz (sistem çağrıları farklıdır). Linux kodunu bir stsarting noktası olarak kullanması tavsiye etti. 32-bit Mac OS/X için bir montaj dili öğreticisine gerçekten ihtiyacınız var Bir makul başlangıç noktası şudur: https://filippo.io/making-system-calls-from-assembly-in-mac-os-x/ –
32 -bit OS/X kodu, 64 bit OS/X'de çalışır. Eğer gerçekten 64-bit OS/X kodu oluşturmak istiyorsanız, 'int 0x80' i bırakmak ve' syscall' komutunu kullanmaya devam etmek isteyeceksiniz. Bu int 0x80'den farklıdır. Çağrı kuralı farklıdır ve sistem çağrı numaraları 32 bit OS/X koduyla eşleşmez. 64 bit OS/X kodunu hedefleyen bir eğitici bulmanız gerekiyor. Ayrıca NASM ile '-f macho64' kullanmak zorundasınız. –