Zvláštnosti architektury amd64 (x86-64)
Příklad 75.1. Použití 64-bit systémových volání
# File: example/as/amd64/hello64.s .section .data msg: .ascii "Hello, world!\n" len: .long . - msg .section .text .global _start _start: # Program starting point. Linker looks for _start symbol. pushq $14; pop %rdx # %rdx=14 pushq $msg; pop %rsi # %rsi=msg pushq $1; pop %rdi # %rdi=1 (STDOUT) pushq $1; pop %rax # write(rdi,rsi,rdx) syscall pushq $2; pop %rdi # retval=1 pushq $0x3c; pop %rax # exit() syscall
Příklad 75.2. Použití 32-bit systémových volání
# File: examples/as/amd64/hello.s # Použitá volání .equ SYS_exit, 1 .equ SYS_write, 4 # Standardní proudy .equ STDIN, 0 .equ STDOUT, 1 .equ STDERR, 2 .section .data msg: .ascii "Hello, world!\n" len: .long . - msg .section .text .global _start _start: # Program starting point. Linker looks for _start symbol. movl $SYS_write, %eax # sys_write(ebx=fd, ecx=ptr, edx=len) movl $STDOUT, %ebx # stdout leal msg, %ecx # Message start point movl len, %edx # Message lenght int $0x80 # call kernel movl $SYS_exit, %eax # sys_exit() movl $1, %ebx # return value (only 8 bits) int $0x80 # call kernel