I assembled a simple objective-c file that prints hello to the screen. this is the code:
#import <Foundation/Foundation.h> int main() { NSString* a = [NSString stringWithUTF8String: "hi"]; NSLog(a); return 0; } When I assembled it and converted it into Nasm syntax, this is the output:
section .text default rel extern _OBJC_CLASS_$_NSString extern _NSLog extern _objc_msgSend global _main _main: push rbp mov rbp, rsp sub rsp, 16 lea rdx, [ L_.str] mov dword [rbp - 4], 0 mov rax, qword [ L_OBJC_CLASSLIST_REFERENCES_$_] mov rsi, qword [ L_OBJC_SELECTOR_REFERENCES_] mov rdi, rax call _objc_msgSend mov qword [rbp - 16], rax mov rax, qword [rbp - 16] mov rdi, rax ; rdi has rax mov al, 0 call _NSLog xor eax, eax add rsp, 16 pop rbp ret segment __DATA,__objc_classrefs L_OBJC_CLASSLIST_REFERENCES_$_: dq _OBJC_CLASS_$_NSString segment __TEXT,__cstring L_.str: db "hi" segment .__TEXT,.__objc_methname L_OBJC_METH_VAR_NAME_: db "stringWithUTF8String:" segment __DATA,__objc_selrefs L_OBJC_SELECTOR_REFERENCES_: dq L_OBJC_METH_VAR_NAME_ segment __DATA,__objc_imageinfo L_OBJC_IMAGE_INFO: dd 0 dd 64 I understand most of it, like the different objc segments, but I dont understand things like mov rax, qword [rbp - 16] or even mov al, 0. This is 64 bit assembly code so why is the register al referenced? and why is [rbp-16] stored into rax?