下面是一个用于苹果 macOS(原為 OS X)的 64 位元程序,用于输入按键并将其显示在屏幕上:
global_startsection.dataquery_string:db"Enter a character: "query_string_len:equ$-query_stringout_string:db"You have input: "out_string_len:equ$-out_stringsection.bssin_char:resw4section.text_start:movrax,0x2000004; put the write-system-call-code into register raxmovrdi,1; tell kernel to use stdoutmovrsi,query_string; rsi is where the kernel expects to find the address of the messagemovrdx,query_string_len; and rdx is where the kernel expects to find the length of the message syscall; read in the charactermovrax,0x2000003; read system callmovrdi,0; stdinmovrsi,in_char; address for storage, declared in section .bssmovrdx,2; get 2 bytes from the kernel's buffer (one for the carriage return)syscall; show user the outputmovrax,0x2000004; write system callmovrdi,1; stdoutmovrsi,out_stringmovrdx,out_string_lensyscallmovrax,0x2000004; write system callmovrdi,1; stdoutmovrsi,in_charmovrdx,2; the second byte is to apply the carriage return expected in the stringsyscall; exit system callmovrax,0x2000001; exit system callxorrdi,rdisyscall